Expand description
Keyboard and pointing-device detection.
Linux reads /proc/bus/input/devices, a single file listing every evdev node with its
handlers and capability bitmaps. Classification is deliberately exclusive: a device is
reported as a keyboard or a mouse or neither, never both.
§Why a device can be unclassifiable
A peripheral paired through a Logitech Unifying/Bolt receiver is presented by the kernel with a merged capability set — the receiver synthesizes one descriptor covering every device class it can carry. Measured on a Bolt receiver carrying an MX Keys keyboard and an MX Master 3 mouse, every kernel-visible signal is identical for the two:
| source | MX Keys (keyboard) | MX Master 3 (mouse) |
|---|---|---|
/proc/bus/input/devices handlers | sysrq kbd leds mouse6 event26 | sysrq kbd leds mouse5 event25 |
capabilities/rel | 0x1943 | 0x1943 |
capabilities/key (alphabet block) | present | present |
udev ID_INPUT_* | POINTINGSTICK | POINTINGSTICK |
USB HID bInterfaceProtocol | 00 | 00 |
| HID report descriptor prologue | 05 01 09 06 a1 01 | 05 01 09 06 a1 01 |
So capability inspection alone cannot separate them, and a classifier that guesses gets
it wrong in both directions (fastfetch 2.66 reports the MX Master 3 as a keyboard and the
MX Keys as a mouse on this hardware). The one place the truth survives is the HID++
driver’s battery model_name ("MX Keys Wireless Keyboard" / "Wireless Mouse MX Master 3"), so that is consulted as a tiebreak — and when it is absent too, the device is
reported in neither field rather than asserted into the wrong one.
Structs§
- Input
Device - One record from
/proc/bus/input/devices.
Enums§
- Device
Kind - What a device was classified as.
Functions§
- classify_
device - Classifies one device, consulting
model_nameonly when the capabilities are ambiguous. - classify_
input_ devices_ with - Classifies a whole device list into
(keyboards, mice), de-duplicated by name. - detect_
input_ devices - Detects connected keyboards and pointing devices as
(keyboards, mice). - has_
alpha_ block - Returns whether a key bitmap covers the whole alphabetic block ([
ALPHA_KEYS]). - parse_
bitmap - Parses a
B: …=capability bitmap into 64-bit words, least-significant word first. - parse_
input_ devices - Parses the whole of
/proc/bus/input/devicesinto records.