'How to inject in JEST interior dependency in service in NestJs
Solution 1:[1]
There is no such concept such as "main keyboard" in Windows API. All keyboard button presses are posted to message queue as WM_KEYDOWN/WM_KEYUP and WM_INPUT. With RawInput you can distinguish which keyboard sent particular input - but it is your decision which keyboard you want to hear (you can filter by keyboard handle for example).
Some mouse devices or USB mouse receivers can emulate HID keyboard for special things like macros or hotkey press etc. Thats probably why you're seeing second keyboard in a list.
Second one would be to try to differentiate the "main" keyboard based on number of keys. Issue is that this also seems a bit hacky as keyboard could vary in number of keys easily.
You cannot detect how many keys keyboard really have. RID_DEVICE_INFO_KEYBOARD has same fake info for any HID keyboard.
You can look at my test code here for example how to differentiate devices.
Also note that in some cases device handle is not provided with WM_INPUT. See details here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |


