Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do the `values` for `MSC_SCAN` in `evdev` come from?

If you run something like

sudo evtest /dev/input/event7

where event7 corresponds to (say) a keyboard and you press a key, you get a report like:

Event: time 1725511187.487035, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70004
Event: time 1725511187.487035, type 1 (EV_KEY), code 30 (KEY_A), value 1
Event: time 1725511187.487035, -------------- SYN_REPORT ------------

for an a key press

and

Event: time 1725511187.543033, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70004
Event: time 1725511187.543033, type 1 (EV_KEY), code 30 (KEY_A), value 0
Event: time 1725511187.543033, -------------- SYN_REPORT ------------

for an a key release.

I'm interested in the value for MSC_SCAN (presumably these are evdev scancodes), where those (hexademical) values are something like 70004, 70005, 70006, 10086, c0224, etc.

These values seem to be directly related to USB HID keycodes, where:

  • values x in the Keyboard/Keypad Page (0x07) are 0x70000 | x (eg. the USB HID keycode for a is 0x04, and 0x70000 | 0x04 is 0x70004)
  • System Control values x are 0x10000 | x
  • values x in the Consumer Page (0x0c) are 0xc0000 | x

So my question is: where do the "base values" 0x70000, 0x10000, and 0xc0000 come from, and where does the 0x70000 | x logic come from?

Eg. (on Ubuntu 20) the value for KEY_A is 30 (decimal), and the 30 comes from /usr/include/linux/input-event-codes.h, where there's a #define KEY_A 30.

(I'm writing firmware for a USB HID device and I'm writing the USB HID Report Descriptors, and so far I can add Keyboard/Keypad keys (USB HID Page 0x07), System Control keys (USB HID Page 0x01), Consumer Control keys (USB HID Page 0x0c), and a mouse, and I'm trying add the Unicode page as well (USB HID Page 0x10), but for some reason evdev isn't recognizing it.)

like image 783
étale-cohomology Avatar asked Nov 17 '25 17:11

étale-cohomology


1 Answers

I think they are precisely the HID Usage Pages, where the 4 least-significant nibbles are the HID keycode, and after that is the HID Usage Page (so, as usually, you read the number right-to-left).

Eg.:

  • 0x70000 comes from Usage Page 0x7: Keyboard/Keypad Page
  • 0x10000 comes from Usage Page 0x1: Generic Desktop Page, and, specifically, System Control)
  • 0xc0000 comes from Usage Page 0xc: Consumer Page

So Linux is basically or'ing the whole HID information into a single keycode and calling it a scancode.

like image 126
étale-cohomology Avatar answered Nov 20 '25 15:11

étale-cohomology