Jump to content
Flirc Forums

Derive HID page and key code from key press events on Linux

Recommended Posts

Use this guide to derive the HID page and key code of an HID event device or original remote connected e.g. via USB, I2C or Bluetooth to a Linux PC, or to verify that your Flirc actually sends the events you expect.

HID page and key code can be grabbed under Linux following these steps:

1. Find the event devices associated with your HID devices using "udevadm info -a <device>" with <device> walking through /dev/input/event*. There might be multiple devices for a single hardware component, e.g. for a Harmony Hub there is one for HID mouse events, one for HID keyboard events, one for HID consumer control events, one for HID system control events, ...

2. Monitor the desired event devices (usually requires root) using "sudo evtest [--grab<] <device>" for each device required. The optional parameter "--grab" is essential if you want to stop the recorded events to be forwarded to and interpreted by the system, like I did to stop my system going into standby whenever I sent the sleep event that I wanted to record. If you want to use "--grab" on your local keyboard or such, you might want to either attach a second keyboard or run the command over the network via SSH, so you can abort the monitoring by sending Ctrl+C.

3. Perform the key presses on the device you want to record. Each key press will emit 2 events, one for key down (press), one for key up (release), example output for the "0" key:

Event: time 1593381762.020128, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70027
Event: time 1593381762.020128, type 1 (EV_KEY), code 11 (KEY_0), value 1
Event: time 1593381762.020128, -------------- SYN_REPORT ------------
Event: time 1593381762.020198, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70027
Event: time 1593381762.020198, type 1 (EV_KEY), code 11 (KEY_0), value 0
Event: time 1593381762.020198, -------------- SYN_REPORT ------------

4. Interpret the output; you are interested in the value of the MSC_SCAN (scancode) of EV_MSC (miscellaneous) events. The value is hexadecimal and for HID devices with the last 4 digits being the HID key code (0x0027) and leading digit(s) the HID page (0x07).

5. HID page 0x07 events (HID keyboard) can be programmed using "flirc_util record_api <modifiers> <key code>", where <key code> is the decimal representation of the HID key code you fetched above (e.g. 0x27 = 39), and <modifier> is a logical or-ed list of modifier keys to be held down while <key code> is sent (see "flirc_util help record_api").

I ran into an intentional limitation of flirc_util, limiting <key code> to values <= 101. Unfortunately, flirc_util silently programs the key anyway without a warning, leaving a key that is never sent.

This cost me a lot of time while trying to send the correct codes to my hardware, being the Flirc the culprit by never sending the programmed keys.
Jason is currently checking whether the limitation will be removed.

Edited by Cru
Removed typos.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...