If the USB device itself presents a HID keyboard interface, then from the point of view of the computer, it is (or "contains") a keyboard. The corresponding HID driver is loaded. The device communicate through that interface using the corresponding HID protocol.
USB devices can have many interfaces. The device itself sends information to the operating system describing what it is, in USB descriptors. You can see that information in the verbose output of lsusb (lsusb -v
). The relevant values are bDeviceClass
, bDeviceSubClass
bDeviceProtocol
.
Here is one of the interfaces of my mouse for instance, presenting itself as a keyboard. When buttons assigned keys or macros are clicked the mouse "type" here :
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 1 Boot Interface Subclass
bInterfaceProtocol 1 Keyboard
iInterface 0
And it is listed by xinput
just like an actual second keyboard.
This also has the potential to be used maliciously, as something doesn't have to look like a keyboard at all to type things for you (or presents itself as any other device).