7

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 Answers3

8

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
taliezin
  • 9,275
  • i have xset, but how do i change the value for Caps Lock? – user115806 Jun 05 '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 05 '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 05 '15 at 14:35
  • @taliezin how to bind Caps to the script? found this http://askubuntu.com/questions/15050/how-do-i-bind-sh-files-to-keyboard-combination 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 08 '15 at 12:46
  • Can you try first running script from command line: CustomScript.sh caps ? – taliezin Jun 08 '15 at 13:17
  • in Terminal - [rahul@345 bin]$ sh CustomScript.sh CustomScript.sh: line 19: [: 0: unary operator expected [rahul@345 bin]$

    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
  • You have to put argument after script: "caps" or "num", e.g: CustomScript.sh caps – taliezin Jun 08 '15 at 13:34
  • Bingo! it worked. Oh i get it..$key has the value of parameter passed to script. – user115806 Jun 08 '15 at 13:57
  • @taliezin xdotool didn't work properly once i change that code in myconf.xkb !allowexplicit to allowexplict i get lot of errors can't proceed further. any other solution? – user115806 Jun 10 '15 at 12:30
  • You can post another question because I don't understand you. – taliezin Jun 10 '15 at 12:46
  • ok. I was referring to [this] answer (http://unix.stackexchange.com/a/179378/117312). on how to change the state with xset. – user115806 Jun 12 '15 at 09:00
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 
HalosGhost
  • 4,790