Get keyboard scancodes in recent versions of linux

I'm trying to find out the scancodes for a set of foot pedals so that I can rebind them to more useful keys. In older versions of Ubuntu I was able to do this using /lib/udev/keymap as discussed here, but the program seems to no longer exist! Luckily I still know what the scancodes are for my specific hardware so I can still get everything working, but I want to write a post about how to set up foot pedals.

The arch-linux wiki suggests using showkey --scancodes but that seems to give me the wrong numbers (by comparing with the known, working scancodes that I'm currently using in my /etc/udev/hwdb.d/90-custom-keyboard.hwdb file):

                           hex        decimal
scancode used in config   0x70004      458756
showkey -s output         0x5d             91
xev keycode                               191

since it's similar to the X keycode I guess that X11 is interfering somewhere.

Is there an alternative way of finding the scancodes? Preferably one that doesn't involve using virtual consoles.


sudo evtest

should give you a list of devices you can get scancodes for. One of them should have the foot pedal's name, so input the eventnumber you can see beside it. Then, once you use the pedal, you should see the scancode on the screen (after "(MSC_SCAN), value"). For example, here:

Testing ... (interrupt to exit)
Event: time 1413649733.746534, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70005
Event: time 1413649733.746534, type 1 (EV_KEY), code 48 (KEY_B), value 1

It's "70005".