I want to trigger a Keypress on a Keyboard. On the physical keyboard - so that it has to travel through all the Kernel Filters with that specific keyboard as its source. Is something like that even possible?
I looked at DeviceIOCtrl and IOCTL_KEYBOARD_INSERT_DATA, but there are no docs to be found. Some say, it is not implemented in the driver. Another Source tries to use IOCTL_INTERNAL_I8042_KEYBOARD_WRITE_BUFFER, but also say, it might not be usable for that kind of stuff.
Are there other options to trigger a keypress on a Keyboard before it travels trough the Kernel Filters?
Why would I even want to do this? Yes this might be an X-Y Question, but its the only solution path I can think of at the moment. I want to intercept keys from a specific keyboard only. There is RawInput, which tells me the Keyboard of a keystroke, but can't intercept it, and there is a LowLevel Keyboard hook that can intercept, but is unable to identify the keyboard. To make matters worse, the RawInput fires after the LowLevel-Hook does, so it is not possible to get the Keyboard before intercepting the keystroke. There is some magic unicorn way to use a global Hook that triggers after RawInput, but it looks like a massive pain to deal with all the edge cases.
There is an API out there to intercept keyboard strokes which is what I opted for. It basically installs a driver that allows to intercept keystrokes and get the keyboard id. But: that ID is kinda abitrary and doesn't follow any rules I can utilize to correlate the integer value to a specific keyboard device. E.g. it changes when replugging the device, does not correlate with the \Device\KeyboardClassX, etc. So the user has to actively press a key everytime the keyboard is reconnected / the app is started so that I can figure out which physical keyboard the id actually represents. And I want to avoid that and automagically get the specific device for a ID. My idea was to trigger a keypress in the keyboard(-controller?) and to catch that using the driver and thus correlating an abitrary ID with the Device.
So if there is a different X for my Y, please feel free to suggest. I'd like to avoid all those edge cases where the Magic Unicorn Way of RawInput and GlobalHook doesn't work reliably. Examples in any major language are fine. Maybe there's no way around the UX-Inconvenience of manually pressing a button at the start of the application to identify keyboards...