xev is probably the tool you're looking for.
Xev creates a window and then asks the X server to send it events whenever anything happens to the window (such as it being moved, resized, typed in, clicked in, etc.). You can also attach it to an existing window. It is useful for seeing what causes events to occur and to display the information that they contain; it is essentially a debugging and development tool, and should not be needed in normal usage.
It prints the full event contents like this for example:
MotionNotify event, serial 38, synthetic NO, window 0x1a00001,
root 0x1ff, subw 0x0, time 11360240, (108,129), root:(1078,148),
state 0x0, is_hint 0, same_screen YES
or for a key press:
KeyPress event, serial 38, synthetic NO, window 0x1a00001,
root 0x1ff, subw 0x0, time 11362278, (111,107), root:(1081,126),
state 0x0, keycode 24 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 bytes: (61) "a"
XmbLookupString gives 1 bytes: (61) "a"
XFilterEvent returns: False