you can use xev to determine scancodes in X.
Actually, xev does the same under X that showkey does in a Linux console. Problem is, it is interactive, requiring manual inspection of each key. What I'd like is to run a command to dump the mapping of kernel scancodes to X keycode numbers. I think this compiled into the X11 keyboard driver, I'll have to dig through some source code to figure it out.
Also, after doing some digging, it turns out that a modified usbkbd.o driver may not be needed, since the same thing can be accomplished by using setkeycodes.
Here's what I've figured out so far:
The keyboard generates a raw scancode, from 0 - 255, for each key. The kernel has a map that maps these raw codes into kernel scancodes (this is what you see in the large array in usbkbd.c in the kernel source). These can also be set / displayed by running setkeycodes / getkeycodes.
Secondly, the mapped kernel scancode (or keycode) is assigned meaning by one of several methods, depending on what is using the keyboard. This layer is responsible for interpreting not only the keys, but also key combinations (shift, alt, ctrl, etc.)
-- for Console-based programs, this layer of mapping is handled by loadkeys / dumpkeys.
-- for Qt Embedded apps (i.e., Qtopia), it is handled by /opt/QtPalmtop/etc/keycode.tbl
-- under X11, this is set (or displayed) using xmodmap. The settings are stored in the running X server's environment, so any changes need to be re-applied when X is restarted. This is ually done by having a startup script (such as .xinitrc) call xmodmap, pointing to a file such as xmodmaprc.
The difference with X11 is it doesn't look at the kerrnel scancode/keycode, but instead it has it's own mapping of raw scancodes to X11 keycodes (I think -- I guess I could test this by changing some of the kernel scancodes, and seeing if that affects X11 apps).