Display cap lock status, num lock and shift keys in Emacs

Can I show if cap locks and num lock keys are enabled in Emacs? The reason I ask is because I am a lone engineer and FrogPad . The 20-key device uses several sequences of switch keys to have the full functionality of a standard qwerty keyboard. It would be very useful for me to display the state of the shift, caps lock and numlock keys inside emacs. I have googled it and could only find messages regarding reassignment of keys. Is it possible?

+6
source share
3 answers

The lowest keyboard input level received by emacs lisp is the keyboard event , which combines basic code with the emacs modifier on / off settings ( meta , control , shift , hyper , super and alt ). Because of this combination, there seems to be no way for lisp code to find out when you, for example, press and hold the shift key. Also note that there is no representation on CAPS LOCK or NUM LOCK.

On the side, the emacs note does distinguish between newline and Cm , but at a very low level in lisp code, the former is mapped to the latter. See lisp/term/x-win.el (usually located under /usr/share/emacs/NN.X ) if you really want gory details.

So, from within emacs lisp, I find it impossible to do what you want.

However, you can embed text from external commands in the emacs mode line and update them regularly. Thus, in principle, you can find the linux command, which returns the status of lock, shift and numlock, as well as periodic injection into the command line. This probably doesn't suit your needs, as it will not update the model in real time when you press shift, caplock and numlock. But if you want to do this, check out the implementations of display-time-mode and display-battery-mode .

+2
source

When you run emacs on X Server, you can write C program, continuous control of Shift, Caps and Numlock, when the change happens, print it to stdout. In emacs, run this program as an external process, process its output using the process filter, and finally display the status of Shift, Caps, and Numlock in the mode line.

0
source

This is not possible in portable Emacs, but if you are using X11:

 (require 'dash) (require 's) (defun x-led-mask () "Get the current status of the LED mask from X." (with-temp-buffer (call-process "xset" nil t nil "q") (let ((led-mask-string (->> (buffer-string) s-lines (--first (s-contains? "LED mask" it)) s-split-words -last-item))) (string-to-number led-mask-string 16)))) (defun caps-lock-on (led-mask) "Return non-nil if caps lock is on." (eq (logand led-mask 1) 1)) (define-minor-mode caps-lock-show-mode "Display whether caps lock is on." :global t :lighter (:eval (if (caps-lock-on (x-led-mask)) " CAPS-LOCK" ""))) 
0
source

Source: https://habr.com/ru/post/892421/


All Articles