My Thinkpad T430 has no visible indicator if a num lock/caps lock is on/off is there a way to notify on screen when turned on/off?
3 Answers
You can try getting info with xset:
xset q | grep Caps
Result:
00: Caps Lock: off 01: Num Lock: on 02: Scroll Lock: off
But if no X you can try kbdinfo:
kbdinfo gkbled
Result:
scrolllock:off numlock:on capslock:off
Edit:
If you want to change states with xset
you may check following answer.
Or you can change state using xdotool:
xdotool key Caps_Lock
For onscreen notifier you may check key-mon.
You can try also following script:
#!/bin/bash
#lockkey.sh
sleep .2
case $1 in
'num')
mask=2
key="Num"
;;
'caps')
mask=1
key="Caps"
;;
esac
value="$(xset q | grep 'LED mask' | awk '{ print $NF }')"
if [ $(( 0x$value & 0x$mask )) == $mask ]
then
output="$key Lock is on"
else
output="$key Lock is off"
fi
notify-send "$output"
You can copy script in /usr/local/bin
and bind Caps to run it as:
/usr/local/bin/lockkey.sh caps
and/or Num as:
/usr/local/bin/lockkey.sh num
The T430 may have no CapsLock LED, but the Power LED can be SW controlled (tested with Linux kernel 4.2) and thus abused nicely. First add this to your /etc/rc.local:
echo kbd-capslock >/sys/class/leds/tpacpi::power/trigger
chmod 666 /sys/class/leds/tpacpi::power/brightness
The 1st line takes care of the text console and, as a side effect, turns the LED off initially. To handle X11 the 2nd line permits normal users to control the LED. Then save this code
#!/bin/sh
sleep 0.1
if xset q | grep -q 'Caps Lock: *on'; then
echo 255 >/sys/class/leds/tpacpi::power/brightness
else
echo 0 >/sys/class/leds/tpacpi::power/brightness
fi
as some executable script (e.g. /usr/local/bin/capsled.sh) and in your Desktop settings bind the CapsLock key to run it. Ugly as hell but works (tested with XFCE4). Does anyone know a cleaner way to remap the LED under X11?

- 11
CAPS_STATUS=`xset q | grep -i caps | cut -c 22-24`
#test on $CAPS_STATUS if its on or off

- 4,790

- 1
there was a notification on screen as "Lock is off".
Pressed Capslock key and ran the script again same notification on screen "Lock is off"
– user115806 Jun 08 '15 at 13:29!allowexplicit
toallowexplict
i get lot of errors can't proceed further. any other solution? – user115806 Jun 10 '15 at 12:30