From a bug report I learned about a tool called evtest: listens for and documents events from devices such as keyboards:
evtest No device specified, trying to scan all of /dev/input/event* Available devices: /dev/input/event0: AT Translated Set 2 keyboard /dev/input/event1: Video Bus /dev/input/event2: PS/2 Generic Mouse /dev/input/event3: Apple, Inc Apple Keyboard /dev/input/event4: Apple, Inc Apple Keyboard /dev/input/event5: PixArt USB Optical Mouse [...] Select the device event number [0-24]: 3 Input driver version is 1.0.1 Input device ID: bus 0x3 vendor 0x5ac product 0x221 version 0x111 Input device name: "Apple, Inc Apple Keyboard" [...] Testing ... (interrupt to exit) Event: time 1622014586.354418, type 1 (EV_KEY), code 28 (KEY_ENTER), value 0 Event: time 1622014586.354418, -------------- SYN_REPORT ------------ Event: time 1622014588.314431, type 1 (EV_KEY), code 59 (KEY_F1), value 1 Event: time 1622014588.314431, -------------- SYN_REPORT ------------ éEvent: time 1622014588.402405, type 1 (EV_KEY), code 59 (KEY_F1), value 0 ....
The successor package is evemu-tools:
- evtest - utility to monitor Linux input device events
- evemu-tools - Linux Input Event Device Emulation Library - test tools