0

My employer has a pretty paranoid screen locking policy on Windows machines. There's no way to override the time settings for the lock. My colleagues an I have been experimenting with various homebrew methods to keep the lock from activating. I'd like to have an Emacs process jiggling the mouse cursor and potentially doing other things to fool the system into thinking there's activity.

4
  • One simple solution to your predicament is to be in presentation mode, as screen lock is prevented in that situation. Exercise left to the reader ;-) – rsp Feb 23 at 16:17
  • @rsp Thanks for the suggestion :). Problem is, I want this to also work when my focus is elsewhere. My only assumption is that I have Emacs running in the system. – Wojciech Gac Feb 23 at 16:27
  • Tip: create a presentation consisting of 1 black slide. Save as presentation to quickly start it. Once started use alt-tab or win-key d to switch away and focus on real work. – rsp Feb 23 at 16:35
  • @rsp I'm sure it works, but it seems a bit roundabout. – Wojciech Gac Feb 23 at 16:47
0

I cooked up the following piece of Elisp code. It consists of a lexical closure storing current cursor position and determines inactivity based on periodic comparisons. The closure is launched once every 60 seconds from a scheduler. There are also two commands for enabling and disabling this process. One thing that's missing in this version is that it only looks at the mouse cursor position, so keyboard-only activity is disregarded. I have a vague idea how to incorporate it, based on the keyboard buffer or some such.

;; -*- lexical-binding: t; -*-
(defvar *jiggle-max* 2 "dx/dy maximum increment for cursor jiggling")
(defvar *jiggle-idle-seconds* 60 "interval between invocations")
(defvar *mouse-jiggler* nil "handle for timer cancellation")

(defun make-mouse-jiggler ()
  "Perform a small cursor jiggle if inactivity detected.
Inactivity is detected based on the cursor position stored in a
lexical closure on previous run."
  (let ((old-pos (mouse-absolute-pixel-position)))
    (lambda ()
      (let ((pos (mouse-absolute-pixel-position)))
    ;; If there was no cursor movement since last execution, or if
    ;; this is the first execution, jiggle the cursor
    (when (equal pos old-pos)
      (message "Jiggle...")
      (destructuring-bind (x . y) pos
        (let ((x (+ x (- *jiggle-max* (random (* 2 *jiggle-max*)))))
          (y (+ y (- *jiggle-max* (random (* 2 *jiggle-max*))))))
          (set-mouse-absolute-pixel-position x y)))
      (cl-case system-type
        ((gnu/linux) (shell-command "setleds -F +num; setleds -F -num" nil))
        ((windows-nt)
         (cl-loop
          repeat 2 do
          (shell-command (concat "powershell.exe "
                     "-Command (New-Object -ComObject WScript.Shell)"
                     ".SendKeys('{NUMLOCK}')") nil)))
        (t (message "OS detected: %s. Don't know how to toggle NumLock"))))
    (setq old-pos (mouse-absolute-pixel-position))))))

(defun enable-mouse-jiggler ()
  (interactive)
  (setq *mouse-jiggler* (run-with-timer 0 *jiggle-idle-seconds* (make-mouse-jiggler))))

(defun disable-mouse-jiggler ()
  (interactive)
  (cancel-timer *mouse-jiggler*))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.