The Linux kernel's HTML documentation provides an example that shows how I can set up a user-space keyboard input device using uinput. However, the way the example does it requires that I call ioctl(fd, UI_SET_KEYBIT, ...); for each key event I will emit. In the example, they only emit KEY_SPACE events so only one call is made.
This is both brittle - in the sence that I need to maintain and update my 100s of calls every time a new key is added - and is also redundant. Is there a better way I can set up the new device so that it can emit any key event without me having to specify each key individually?
The header file linux/uinput.h doesn't contain anything that looks like it could help. The kernel's HTML documentation doesn't mention anything relevant either. Any help would be much appreciated.
Using tricks like adding all defined keys by looping through
KEY_ESCtoKEY_MAXmay work but can lead to the input device being unusable in certain situations.One technique I found, employed in
evemu-tools, is to clone from an existing input device when setting up a new uinput device. While this will not allow arbitrary events to be emitted by the new device, it will allow the emitting of all keyboard events supported by the cloned device.For the sake of completeness, I've included a superset of Key Events that I sampled from a few keyboards across multiple kernels, hardware configurations (builtin/usb), and keyboard brands. This superset should be serve as a valid fallback if no other keyboard input device is present on the device to clone from (e.g. mobile phones):
I'm aware that this answer doesn't doesn't cover the general case of arbitrary keyboard events (the title of this question) so I'll be leaving this question open in hope for a proper answer.