kbstate [Updated 2015-12-28]
A small Linux tool to detect keyboad state (=key-pressed state) from shell. Useful for detecting various key states, for example, during boot time.
Returns: Names of the keys pressed at that time, e.g.
kbstate will scan through all /dev/input/event* and print out list of shift keys being pressed. The supported keys are
If multiple keys are pressed at the time
kbstate is run, it will print out
all these keys, separated by spaces.
This works both in console and terminal inside X session.
kbstate [Older version]
A small tool to detect keyboad state (=key-pressed state) from shell. Useful for detecting various key states, for example, during boot time.
Returns: 0 if key is pressed, 1 otherwise, 255 for errors.
key is either
rctrl (that's left/right shifts, left/right alts, left/right controls)
in English keyboard, not sure the equivalents in others.
You can edit the source to add other keys too.
devpath is the path to the Linux's keyboard event device.
The default value is
(that is, the built-in keyboard port) but most of the time you would need to
/dev/input/event5 or something if you use USB keyboard.
/proc/bus/input/devices to find devices whose "handlers" is "kbd",
on the same line is the "eventXXX" to be used for that device (accessed
/dev/input/eventXXX which you pass to kbstate).
If you need to check multiple keyboards (PS/2, USB, etc)
you will need to call kbstate multiple times, one for each devpath.
This tool originally came from here, I have just tidied up a little to make it more readable.
Originally posted here: Detecting keyboard state in shell.