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.
Главное
- 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
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.
Частые вопросы
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.
Как мы берём на себя linux desktops and user land infrastructure
Мы разбирались с этим сотни раз: Hardening compositors, sandboxing desktop apps, and tuning the user land that developers and operators actually touch. С услугой Администрирование серверов и Обслуживание сайтов вы получаете полный цикл: мы оцениваем, внедряем, следим круглосуточно и подключаемся в течение 30 минут, когда это действительно нужно.