Xev
The xev program displays X events. It can create its own window or grab events sent to some other window. Xev is useful for debugging X applications or X server configurations.
The events seen by xev include key presses (and releases), mouse motion and button presses (and releases) (including specifically when the mouse enters and leaves the window), focus changes, and redraw requests.
You can use it to find out key codes that you do not know, e.g. if you want to set the mute/audio raise/audio lower button on your laptop as described at Configuring_keyboards#Enabling_Keyboard_Multimedia_Keys
Example
To know the keycodes of key pressed you can do:
xev | gawk '/keycode/{if($0!=l)print;l=$0;}'
The gawk script deletes successive identical lines ( key release events often generates identical lines ).
Note: If xbindkeys is running it can grab the keys before xev has even a chance to report on them.