开发者

Is it possible to block keyboard input selectively in Windows? How?

My app (in C#) need to interface with a U开发者_Go百科SB bar-code scanner, which is basically working like a keyboard. It inputs the bar-code with an enter key at the end.

The app need to be work even when it's at background, so I am using low level keyboard hook to get and filter the bar-code out in the global key events. This part is already working.

Here is my problem: I don't want other apps to get the keyboard(scanner) inputs if it is a bar-code. And the normal key events should not be interfered. In one word, block the key events selectively. Is this possible?

My app is in C#, but I have no problem with C++ or more native solutions as long as it's easy to integrate in C#.

Thanks.

Additional Information:

  1. The whole idea is working at background, even when it's not active. It watches the global key events stream and spot the bar-code sequence (already implemented with Hook). And most importantly, it do NOT interfere with normal keyboard events nor other applications' operation. That's why I cannot block all the key events or make it top-most.

  2. I already can get the bar-code. I need to prevent other applications from getting the bar-code.


At the end of your keyboard hook you would call CallNextHookEx to execute next hook in the chain.

I would suggest that put some unique signature as a preamble for your barcode so that your keyboard hook procedure can detect it as a valid barcode input from your scanner. Now, when you get this data, just skip the call to 'CallNextHookEx' so that the chain will be discontinued and other programs won't get your barcode. Otherwise - call 'CallNextHookEx' so the chain can continue.

Note: This is my theory, I have never tried the exact same thing myself. I have however, written hooks in C++ and C#.


Check this project out http://globalmousekeyhook.codeplex.com/

It is in C# as well so will make your coding easier. Sounds like all you need is to hook up the global key press event and suppress it by setting the Handled value or something similar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜