Xev

From wikinotes

xev displays the keycode produced by a keypress within Xorg.
For TTYs, see showkey.

Usage

NOTE:

You also can type characters following cat -E to obtain raw-ansi-escape codes.

xev                  # watch all events (mouse + keyboard)
xev -event keyboard  # watch only keyboard

Example keycode result for Alt+L

KeyRelease event, serial 27, synthetic NO, window 0x1200001, root 0x101, subw 0x0, time 6417474, (340,373), root:(342,393), state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False