5

I was looking for a list of keyboard scancodes in the linux kernel sources, but I did not find anything. Does someone know where to find these? Especially the USB scancodes would be interesting.

defoe
  • 153
  • I might have found a list in /include/uapi/linux/input.h but it does not contain the actual keycodes. – defoe Nov 28 '13 at 14:07

1 Answers1

7

The keycodes are in [src]/drivers/tty/vt/defkeymap.map:

# Default kernel keymap. This uses 7 modifier combinations.
[...]

See also my answer here for ways to view (dumpkeys) and modify (loadkeys) the current keymap as it exists in the running kernel.

However, those are a bit higher level than the scancodes sent by the device. Those might be what's in the table at the top of [src]/drivers/hid/hid-input.c, however, since they come from the device, you don't need the linux kernel source to find out what they are; they are the same regardless of OS.

"HID" == human interface device. The usbhid subdirectory of drivers/hid doesn't appear to contain any special codes, since USB keyboards are really regular keyboards.

One difference between keycodes and scancodes is that scancodes are more granular -- notice there's a different signal for the press and release. A keycode corresponds to a key that's down, I believe; so the kernel maps scancode events to a keycode status.

goldilocks
  • 87,661
  • 30
  • 204
  • 262
  • Okay, that seems to be what I was looking for, thanks. But I still miss the actual scancode, probably I just mix up things. I learned here that when I press ENTER on my USB keyboard, the scancode 1C is sent to the kernel. But I don't seem to find 1C in /drivers/tty/vt/defkeymap.map. Is there another layer between them? – defoe Nov 28 '13 at 15:02
  • Whoops, I confused keycodes and scancodes -- have edited that in. Decimal 28 is hexadecimal 1C. – goldilocks Nov 28 '13 at 15:23
  • ...notice 1C is the IBM PC XT "Return pressed" from that wikipedia link. – goldilocks Nov 28 '13 at 15:27