I am using the Raw Input API because I need to be able to respond to keys from different USB HID devices differently, even if it is the same key.
My
As written above, there is no direct possibility, but you can make it by combining low-level keyboard hooks.
In my case, I need to catch code from barcode scanner so that's only digits and ENTER.
My solution is that RawInput captures all keys only from barcode scanner device, and keyboard hookup captures only digits 0-9 and ENTER and does not return it at all. Then, inside the code, I'm deciding whether key needs to be returned or not by:
SendKeys.SendWait("{ENTER}");
You can "swallow" some key-press only by writing a kernel keyboard filter driver. So, if you are still in that you'll need a DDK.
The Raw Input API does not support swallowing of keypresses.
Furthermore, it does not interact with SetWindowsHookEx
within the same process. As soon as the Raw Input API is initialized, the hook is unhooked.
The solution is to have them in separate processes. One process can use SetWindowsHookEx
to swallow the unwanted keys, while another uses the Raw Input API to process the keypresses that do come through. Then you just run both. This worked just fine for me.