Windows expects keyboards and mice to appear as standard USB (or Bluetooth, etc.) Human Interface Devices (HID). If the device’s USB descriptors and HID report descriptors conform to the HID usage tables for keyboard and mouse, Windows will automatically bind its in-box drivers and the device will work without any custom driver.
Key points for a custom keyboard/mouse over USB:
- HID device class
- Implement the USB HID class on the device.
- Use the standard HID usage pages and usages for keyboard and mouse:
- Keyboard: HID usage page for Generic Desktop / Keyboard usages.
- Mouse: HID usage page for Generic Desktop / Pointer / Mouse usages.
- Define one or more top level collections (TLCs) in the HID report descriptor:
- A pure keyboard can expose a keyboard TLC.
- A pure mouse can expose a mouse TLC.
- A combo device (keyboard with integrated pointing device) exposes multiple TLCs (for example, one for keyboard, one for mouse). Windows will create a separate PDO (logical device) for each TLC.
- How Windows builds the driver stack
- The USB transport stack enumerates the device and creates a physical device object (PDO), then loads the HID transport driver and
HIDCLASS.sys (the HID class driver).
-
HIDCLASS.sys parses the HID report descriptor and creates a PDO for each keyboard or mouse top level collection.
- For each keyboard TLC, Windows loads
KBDHID.sys (HID keyboard mapper driver), which converts HID usages into keyboard scan codes.
- For each mouse/touchpad TLC, Windows loads
MOUHID.sys (HID mouse mapper driver), which converts HID usages into mouse movement/buttons/wheel commands.
-
KBDHID.sys then loads KBDCLASS.sys (keyboard class driver), which provides the OS-level keyboard functionality.
-
MOUHID.sys then loads MOUCLASS.sys (mouse class driver), which provides the OS-level mouse functionality.
- As long as the device presents a valid HID keyboard/mouse TLC, no vendor-specific driver is required.
- No vendor driver needed if HID-compliant
- For standard keyboard and mouse behavior, vendor drivers are not required if the device is compliant with the supported HID usages and top level collections.
- This means the firmware must:
- Expose correct USB device/interface descriptors for HID.
- Provide a correct HID report descriptor describing keyboard and/or mouse reports.
- Send input reports that match the descriptor (for key presses, releases, mouse movement, buttons, wheel, etc.).
- Keyboard layout vs. hardware
- The physical key matrix and scan codes are abstracted by Windows.
-
KBDHID.sys maps HID usages to scan codes; KBDCLASS.sys and the configured keyboard layout map scan codes to characters.
- The “layout” (language, key labels, etc.) is configured in Windows, not in the device firmware. The device just needs to send the correct HID usages for each key.
- Accessing raw input in applications (optional)
- Applications that need device-specific data can use the Raw Input API.
- In the traditional model, Windows converts device-specific data to device-independent messages (for example,
WM_CHAR, WM_MOUSEMOVE).
- With Raw Input, applications register for devices and receive raw HID data via
WM_INPUT, allowing them to distinguish between multiple keyboards/mice and process low-level data directly.
- This does not change how the hardware must present itself; it still needs to be a proper HID keyboard/mouse for Windows to enumerate it as such.
- Other transports
- HID is bus-agnostic. The same HID model applies over USB, Bluetooth, and other supported transports.
- On Windows,
HIDCLASS.sys is the glue between the HID client drivers (keyboard/mouse mappers) and the various transports.
- If a non-standard protocol is used
- If the device does not conform to HID keyboard/mouse usages, Windows will not treat it as a standard keyboard or mouse.
- In that case, a custom driver (for example, using WinUSB or a vendor-specific driver) and custom software would be required, but it would no longer behave as a system keyboard/mouse.
For a lab-built keyboard/mouse that “just works” on Windows and integrates with existing systems, the practical path is:
- Implement USB HID class in firmware.
- Use standard HID usage pages/usages for keyboard and mouse.
- Define correct HID report descriptors for keyboard and/or mouse TLCs.
- Ensure reports match the descriptors.
Windows will then automatically load HIDCLASS.sys, KBDHID.sys/MOUHID.sys, and KBDCLASS.sys/MOUCLASS.sys, and the device will be recognized as a normal keyboard and/or mouse.
References: