How to identify if Num lock or Caps lock is turned on in RHEL 6.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

Tags:

Gui