I'd like to post a summary of the various tools I've just tested.
I began with this google search: linux see what key is being pressed, which brought me to the following places. Since they are either closed or off-topic, right here is the most-logical choice to post my summary.
- [closed: off-topic] https://superuser.com/questions/248517/show-keys-pressed-in-linux
- [closed: duplicate] https://askubuntu.com/questions/1197651/ubuntu-show-what-keys-are-pressed-in-real-time
- [the "original", non-duplicate question] https://askubuntu.com/questions/30466/how-can-i-display-keyboard-shortcuts-as-i-press-them
- this very question here
Here is a bit of a summary of the best answers from each of those places. I need this info. so I can:
- detect stuck keys, which just happened, and
- work on HID keyboard microcontroller devices, which I do occasionally since I sell one.
Summary of various ways to detect key presses
Tested on Linux Ubuntu 20.04.
screenkey# Install it sudo apt update sudo apt install screenkey # run it screenkey # it now displays a massive black bar at the bottom of your main monitor # whenever you press any key, showing all keys as they are pressed! # kill it # first, find its PID ps aux | grep screenkey # Sample output: # $ ps aux | grep screenkey # gabriel 215523 2.9 0.3 972900 59364 ? Rl 10:27 0:00 /usr/bin/python3 /usr/bin/screenkey # gabriel 215635 0.0 0.0 9040 2388 pts/0 S+ 10:27 0:00 grep --color=auto screenkey # OR pgrep screenkey # Sample output: # $ pgrep screenkey # 215523 # now, kill that PID; ex: kill 215523Where I first learned about this tool: https://askubuntu.com/a/30468/327339
sudo showkey# show numeric keycode key presses and releases (use Ctrl + C to exit) sudo showkey # show hex scancodes (use Ctrl + C to exit) sudo showkey -s # show ASCII keycodes, including the actual letter or character pressed, # which is the most human-readable (use `Ctrl + D` to exit, NOT `Ctrl + C`!) sudo showkey -aSource:
- https://superuser.com/a/248568/425838
- My summary comment under the answer: https://superuser.com/questions/248517/show-keys-pressed-in-linux#comment2606625_248568
- https://superuser.com/a/248568/425838
https://www.keyboardtester.com/. Test your keys in the browser, and/or see if a key is stuck. Where I first learned about this tool: https://askubuntu.com/a/1197656/327339
xev. When done using it, it takes two steps to kill it:- Click out of your current terminal window to cause your terminal window to lose focus.
- Click back into your terminal window and press Ctrl + C.
Sources:
- Where I first learned about this tool: https://askubuntu.com/a/1198027/327339
- See also: How to detect global key presses
sudo evtest- a very low-level tool; appears to be what I need to work on USB HID devices (I think); works great!# Install it sudo apt update sudo apt install evtest # Run it # First, find your keyboard /dev/input/event number manually sudo evtest # Then, press Ctrl + C to kill it after it prints out all the events; you # do NOT need to "Select the device event number" as it requests. Just hit # Ctrl + C. # Let's assume ours is "/dev/input/event4". # now, run the grab command with the above event number path sudo su -c 'sleep 1; timeout -k5 10 evtest --grab /dev/input/event4' # OR, if you know that `sudo evtest` only shows one output line with the # word "keyboard" in it, you can script the above two steps with this one # cmd like this. Notice that you can get a list of all input devices with # `cat /proc/bus/input/devices`, as is done at the start of this cmd: input_event_num="$(cat /proc/bus/input/devices \ | grep -B 1 -A 10 -i "keyboard" | awk 'NR==6 {print $4}')"; \ path_to_keyboard="/dev/input/$input_event_num"; \ sudo su -c "sleep 1; timeout -k5 10 evtest --grab $path_to_keyboard"Source:
- https://askubuntu.com/a/1197742/327339
- See also the comments under this answer.
- https://askubuntu.com/a/1197742/327339
Other references:
awkhelp: https://unix.stackexchange.com/a/89641/114401- Where I learned about
cat /proc/bus/input/devices: https://stackoverflow.com/a/15052092/4561887