5

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?

6

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
  • i have xset, but how do i change the value for Caps Lock? – user115806 Jun 5 '15 at 13:32
  • @user115806 I added link to answer for changing state of Caps Lock. But in your question you want only to check states. – taliezin Jun 5 '15 at 13:52
  • that's a very well written answer. I'll rephrase my question and my T430 doesn't have LED's to indicate its on/off so i thought if there's a way to notify on screen when caps lock is pressed. I also came across "notify-send" is there a way when i press caps lock and it shows up on my screen.? – user115806 Jun 5 '15 at 14:35
  • @taliezin how to bind Caps to the script? found this askubuntu.com/questions/15050/… used Compiz Config Settings Manager to bind the CapsLock key placed your script as CustomScript.sh in /usr/local/bin and did Chmod+x CustomScript.sh it didn't work :( – user115806 Jun 8 '15 at 12:46
  • Can you try first running script from command line: CustomScript.sh caps ? – taliezin Jun 8 '15 at 13:17
1

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?

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

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.