I was having a peculiar issue with my computer where the “]” key kept getting pressed over and over again. It was very aggravating and I wasn’t sure where the problem was coming from. Neither my external keyboard nor the laptop keyboard would respond when I would press the “]” key and I was confused. As part of my investigation, I became aware of a command line tool called “showkey” that helped me figure out what was going on with my computer. I largely lifted this information from the Geeks for Geeks website but I wanted to comment on the details my own way and also describe how I used it to help me.
Installation
I don’t know showkey is not a standalone application for the command line but a part of another package called kbd on openSUSE. It may be the same on other distributions, I haven’t investigated this so I can’t say for sure. Likely, this is not something you will have to install.
Use
The use of showkey is rather simple. You have four options and one of them is to show help.
Simple Use
In the terminal just simply type:
sudo showkey
This will show whatever key you are pressing by it’s keycode:
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]
press any key (program terminates 10s after last keypress)...
keycode 28 release
qkeycode 16 press
keycode 16 release
wkeycode 17 press
keycode 17 release
ekeycode 18 press
keycode 18 release
rkeycode 19 press
keycode 19 release
You may not need anything more than this basic usage as this is all I needed to figure out my problem but I took it as an opportunity to learn more about it.
Help option
This is the help or information about showkey.
showkey -h
This displays the basic help information about showkey.
Usage: showkey [option...]
Options:
-a, --ascii display the decimal/octal/hex values of the keys.
-s, --scancodes display only the raw scan-codes.
-k, --keycodes display only the interpreted keycodes (default).
-t, --timeout set timeout, default 10
-h, --help print this usage message.
-V, --version print version number.
Report bugs to authors.
Ascii
I believe that this might be the most informative of the options. It gives you all the juicy details of what key it is your are pressing.
showkey -a
This shows not only the letter your are pressing but also the associated decimal, octal, and hex values of the key press. I mostly just want to see the letter I am pressing but the other things are cool too.
Press any keys - Ctrl-D will terminate this program
q 113 0161 0x71
w 119 0167 0x77
e 101 0145 0x65
r 114 0162 0x72
t 116 0164 0x74
y 121 0171 0x79
^D 4 0004 0x04
Note that this option will not timeout on its own, you will have to press CTRL+D to exit the program.
Scancodes
The -s option shows the raw scancodes.
showkey -s
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]
press any key (program terminates 10s after last keypress)...
0x9c
q0x10
0x90
w0x11
0x91
e0x12 0x92
r0x13 0x93
t0x14 0x94
What seems to be odd is that sometimes it splits the codes of a single key push into two lines. I don’t know why nor have I investigated it. Maybe it’s something I am doing wrong?
Keycodes
This is also the default option and shows the raw keycode. You’ve already seen this one as it is the most basic.
showkey -k
Timeout
The Default timeout is 10 seconds for the options but if you would like to alter it up or down, it is easily accomplished with the -t option and an associated time in seconds. In this case showkey will timeout after 5 seconds.
showkey -t 5
kb mode was ?UNKNOWN?
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]
press any key (program terminates 5s after last keypress)...
keycode 28 release
akeycode 30 press
keycode 30 release
jkeycode 36 press
keycode 36 release
ikeycode 23 press
Other than the -a option, you can tack on -s or -k options to get the timeout of your choosing.
Final Thoughts
This is a little thing that helped me figure out an issue I was having with my keyboard. It turned out that I was a bit negligent and I discovered that my secondary keyboard was pressed up against my IMSAI 8080 Replica beneath my desk. It was a silly thing that derailed my day for about 20 minutes but now I have a new tool to debug or investigate input.
References
https://kbd-project.org/
https://www.geeksforgeeks.org/showkey-command-in-linux-with-examples


Leave a Reply to Check keyboard codes – cubicleate techpad - Top4AllCancel reply