Skip to main content

Module input

Module input 

Source
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:

sourceMX Keys (keyboard)MX Master 3 (mouse)
/proc/bus/input/devices handlerssysrq kbd leds mouse6 event26sysrq kbd leds mouse5 event25
capabilities/rel0x19430x1943
capabilities/key (alphabet block)presentpresent
udev ID_INPUT_*POINTINGSTICKPOINTINGSTICK
USB HID bInterfaceProtocol0000
HID report descriptor prologue05 01 09 06 a1 0105 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§

InputDevice
One record from /proc/bus/input/devices.

Enums§

DeviceKind
What a device was classified as.

Functions§

classify_device
Classifies one device, consulting model_name only 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/devices into records.