Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created October 3, 2025 09:37
Show Gist options
  • Save danielrosehill/0cfdfa7ec7097116163b43e883f2ffd2 to your computer and use it in GitHub Desktop.
Save danielrosehill/0cfdfa7ec7097116163b43e883f2ffd2 to your computer and use it in GitHub Desktop.

Macropad Button to F13 Key Mapping

Problem

A macropad (HID 5131:2019) was sending KEY_2 (scancode 7001f) when a button was pressed, but needed to send F13 instead.

Solution

Use udev's hwdb (hardware database) to remap the scancode to F13.

Steps

  1. Identify the device and scancode

    # Find your device
    cat /proc/bus/input/devices | grep -A 5 "5131:2019"
    
    # Monitor keypresses to get scancode
    sudo evtest /dev/input/eventX  # Replace X with your device event number
  2. Create hwdb rule Create /etc/udev/hwdb.d/90-macropad.hwdb:

    # Remap macropad button 2 to F13
    # Device: HID 5131:2019
    evdev:input:b0003v5131p2019*
     KEYBOARD_KEY_7001f=f13
    

    Important: The line with KEYBOARD_KEY_7001f=f13 must start with a single space, not a tab.

  3. Apply the changes

    # Copy the file to the correct location
    sudo cp 90-macropad.hwdb /etc/udev/hwdb.d/
    
    # Update the hardware database
    sudo systemd-hwdb update
    
    # Trigger udev to reload
    sudo udevadm trigger
  4. Test

    • Unplug and replug the macropad, or reboot
    • Press the button - it should now send F13

hwdb Rule Format

evdev:input:b<bus_id>v<vendor_id>p<product_id>*
 KEYBOARD_KEY_<scancode>=<keyname>
  • b0003 = USB bus (0003)
  • v5131 = Vendor ID (5131)
  • p2019 = Product ID (2019)
  • 7001f = Scancode in hex
  • f13 = Target key name (see /usr/include/linux/input-event-codes.h for all key names)

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment