Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the status of caps lock, num lock and shift keys in Emacs

Tags:

emacs

elisp

Is it possible to display whether or not the caps lock and num lock keys are on in Emacs? The reason why I ask is because I am a one-handed typist and use a FrogPad. The 20 key device uses multiple shift key sequences to have the full functionality of a standard qwerty keyboard. I would find it extremely helpful to display the status of the shift, caps lock and numlock keys inside emacs. I have googled this and could only find posts regarding remapping keys. Is this even possible?

like image 566
BasicObject Avatar asked Jul 10 '11 02:07

BasicObject


People also ask

Which displays the status of Num Lock Caps Lock and Scroll Lock?

TrayStatus shows you the status of keyboard keys like Caps Lock, Num Lock, Scroll Lock, Alt, Ctrl, and more, right in your system tray.

Which light indicates the status of Caps Lock?

The green LED on the key is lit, indicating that Caps Lock is on.

How do you change caps and Ctrl?

Select "Keyboard & Mouse" from the left-hand menu. Click "Additional Layout Options". Click "Ctrl position" on the window that opens and choose "Swap Ctrl and Caps Lock."

How to show Num Lock and Caps Lock status indicators on taskbar?

To show the num lock and caps lock status indicators on the taskbar, we are going to use a free software called TrayStatus. The application is pretty lightweight and easy to use. 1. First, get TrayStatus from here. After downloading, double-click on the exe file and follow the installation wizard to install it.

How do I know if my keyboard has Caps Lock?

If your keyboard or laptop has no num lock or caps lock status indicators, you can show the Num Lock and Caps Lock status indicators on the taskbar. Most keyboards and even some laptops have indicator lights for special keys like the num lock, caps lock, and scroll lock.

How to enable or disable Caps Lock and numer lock in outlook?

To do that, click on the “Options” tab on the sidebar. Next, select the “Start with Windows” checkbox. 4. After that, click on the “Status Indicators” tab on the sidebar. This is where you can enable or disable a wide range of status indicators including the num lock and caps lock.

How to enable on-screen display of Capslock and NumLock?

Click on Screen Configurations tab. In Properties window, make sure Enable on-screen display is checked. Under " Indicator settings for NumLock and CapsLock " section, look for " While the numeric lock or caps lock is ON " section, choose the " Show the indicator for a few seconds " option.


2 Answers

It's not possible in portable Emacs, but if you're 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" "")))
like image 151
Wilfred Hughes Avatar answered Sep 22 '22 12:09

Wilfred Hughes


The lowest level of keyboard input received by emacs lisp is the keyboard event, which combines a basic code with the on/off settings of the emacs modifiers (meta, control, shift, hyper, super, and alt). Because of this combination, there appears to be no way for lisp code to learn when you, for example, press and hold the shift key. Note also that there is no representation at all of CAPS LOCK or NUM LOCK.

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

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

However, it is possible to embed text from external commands into the emacs mode line, and to have that updated on a regular basis. So, in principle you could find a linux command that returns caps lock, shift, and numlock status, and periodicaly inject that into the command line. This probably doesn't really meet your needs, since it won't update the modeline in real time as you press shift, capslock, and numlock. But if you want to pursue this, check out the implementations of display-time-mode and display-battery-mode.

like image 29
Dale Hagglund Avatar answered Sep 23 '22 12:09

Dale Hagglund