NOC online · 24/7Longview, TX · +1 323 412 0665
KinetikatechServers · Security · Websites
FR

Ce guide détaillé est disponible en anglais.

English version

Linux Desktops and User Land Infrastructure

Building Custom Linux Input Rules at the evdev Level for Specialized Hardware Macro Arrays

Generic input drivers treat every keyboard the same, which breaks specialized macro arrays that send non-standard scancodes or need per-key remapping. evdev exposes the raw event stream, and udev plus hwdb let you remap at the kernel level before any userspace tool sees the event. This guide builds custom rules for a macro array.

Points clés

  • Identify the device. Use evtest and lsusb to capture the vendor, product, and event types the hardware emits.
  • Write a udev rule. Match by vendor and product ID, then run a helper or set properties such as ID_INPUT_KEYBOARD.
  • Add hwdb entries. Map raw scancodes to standard keycodes in /etc/udev/hwdb.d so the kernel translates them.
  • Rebuild the hwdb. Run systemd-hwdb update and trigger the device to apply changes without a reboot.
  • Test with evtest. Confirm the remapped events appear as the expected keycodes before involving a compositor.
  • Handle chording. Macro arrays often send simultaneous presses; decide whether to synthesize a single key or a sequence.
  • Keep rules in version control. Input configuration is invisible until it breaks, so track every file.
  • Document the scancode map. Future maintenance depends on knowing which raw code maps to which logical key.

Architecture

Input flows from the hardware through the kernel evdev driver, where hwdb remapping occurs, into udev-tagged device nodes, and finally to the compositor or application. Remapping at the evdev level means every consumer sees the corrected events without per-app configuration.

Production configuration

Identify the device and its events bash
lsusb | grep -i macro
sudo evtest /dev/input/eventX
# capture vendor and product IDs
udevadm info -a -n /dev/input/eventX | grep -iE 'idVendor|idProduct'
udev rule and hwdb entry ini
# /etc/udev/rules.d/99-macro-array.rules
SUBSYSTEM=="input", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", ENV{ID_INPUT_KEYBOARD}="1"

# /etc/udev/hwdb.d/99-macro-array.hwdb
evdev:input:b0003v1234p5678*
 KEYBOARD_KEY_70004=a
 KEYBOARD_KEY_70005=b
 KEYBOARD_KEY_70006=c
Apply and verify bash
sudo systemd-hwdb update
sudo udevadm trigger /dev/input/eventX
sudo evtest /dev/input/eventX
# confirm remapped keycodes appear

Edge cases from production

  • Some macro arrays present as multiple input devices; rules must match each one separately.
  • hwdb patterns are case-sensitive and whitespace-sensitive; a trailing space breaks the match silently.
  • Compositors may cache the keymap; restart the session after changing evdev rules.
  • Devices that change product ID between firmware versions need multiple rule entries.

Questions fréquentes

Why remap at evdev instead of in userspace?

evdev remapping applies to every consumer, including the console and remote sessions, without per-app configuration.

Can I send key sequences from one press?

Not at the evdev level; use a userspace daemon such as keyd or kmonad for sequences.

Do hwdb changes require a reboot?

No, systemd-hwdb update plus udevadm trigger applies them immediately.

What if the device is not detected?

Check that the kernel driver binds to it; some devices need a specific driver loaded first.

How do I debug a non-matching rule?

Use udevadm test to see which rules fire and which properties are set.

Comment Kinetikatech vous aide avec linux desktops and user land infrastructure

C'est notre quotidien : Hardening compositors, sandboxing desktop apps, and tuning the user land that developers and operators actually touch. Notre service Gestion de serveurs et Maintenance web le couvre de bout en bout : évaluation, mise en œuvre, supervision 24/7 et intervention d'urgence en 30 minutes.

Parler à un ingénieur

Problème de serveur ? Site piraté ? Site lent ?

Incidents critiques pris en charge en 30 minutes — 24h/24, 7j/7.

Demander une assistance urgente support@kinetikatech.com