mob-i-l
Posts: 263
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Running lights on the keyboard LEDs in X

Wed Sep 11, 2019 3:18 pm

This command line in Raspbian Buster at the Linux console (Ctrl+Alt+F1 in X) shows running lights on the keyboard LEDs:
while true; do setleds +num ; sleep 0.1 ; setleds -num ; setleds +caps ; sleep 0.1 ; setleds -caps ; setleds +scroll ; sleep 0.1 ; setleds -scroll ; sleep 0.7 ; done
(Assuming the LEDs are in order Num Lock, Caps Lock, Scroll Lock.)

What command line would do the same in X?

while true; do xset led named 'Num Lock' ; sleep 0.1 ; xset -led named 'Num Lock' ; xset led named 'Caps Lock' ; sleep 0.1 ; xset -led named 'Caps Lock' ; xset led named 'Scroll Lock' ; sleep 0.1 ; xset -led named 'Scroll Lock' ; sleep 0.7 ; done

But this doesn't work in Raspbian Buster out of the box. You have to modify two files and reboot. Then you can run the command line for running lights on the keyboard LEDs in X.

Code: Select all

sudo sed -i 's|\!allowExplicit|allowExplicit|g' /usr/share/X11/xkb/compat/ledcaps
sudo sed -i 's|\!allowExplicit|allowExplicit|g' /usr/share/X11/xkb/compat/lednum
If you have the LEDs in another order you have to change to for e.g. Caps, Num, Scroll:
while true; do xset led named 'Caps Lock' ; sleep 0.1 ; xset -led named 'Caps Lock' ; xset led named 'Num Lock' ; sleep 0.1 ; xset -led named 'Num Lock' ; xset led named 'Scroll Lock' ; sleep 0.1 ; xset -led named 'Scroll Lock' ; sleep 0.7 ; done

Even if you don't have keyboard LEDs you can test this using the Panel Applet called Keyboard LED and change the preferences of that to have all LEDs. Right click on the panel and choose Add / Remove Panel Items, and then the Add button, and later configure using the Preferences button.

I made a useful discovery. If you turn on the Num Lock LED using xset led named 'Num Lock' and it was off before, then the numeric portion of a laptop keyboard (i.e. using 7890, uiop, jkl;, m,./) works as the numeric part of a full keyboard without Num Lock active, e.g. 9 works as PgUp and L, as PgDn. At least this is the case for the official Raspberry Pi Keyboard. You have to turn it off with xset -led named 'Num Lock'.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

Return to “Other projects”