Is it possible to swallow a key in Raw Input?

馋奶兔 提交于 2019-12-05 10:38:43

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.

As written above there is not direct possibilty, 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 end ENTER.

My solution is that RawInput captures all keys only from barcodescanner 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 wheter 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!