Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How to block keypresses from reaching main form

$
0
0

Hello, I have been writing an application that will capture output from a barcode scanner.  The scanner wedges itself in between the keyboard and the OS and sends the barcode as a sequence of key presses.  This works fine and I easily wrote myself an application to capture these key events.  However, I wanted to be able to capture the events even when my form wasn't focused, to do this I hooked the keyboard events and overrided WndProc to capture the WM_INPUT messages and then I process them, make sure they are coming from scanner, and then I remove the message from the queue using PeekMessage.  This works fine except I have now realized that my form will have to be hidden (invisible) and that other forms will be on top and have focus.  When the scanner reads in a barcode, I don't want the mainform to receive any of those key events, I want my listener to capture them all and then not send the WM_INPUT message down the list.  PeekMessage is supposed to achieve this by sending a WM_REMOVE flag as the last parameter, but it only removes it from the current thread and my listener runs on its own thread separate from the main form, so this doesn't solve the problem as the main form still gets the key presses.

I was wondering if there was any way to block the WM_INPUT messages from reaching the main form or if there was an easy way to cause my listener form (remember, its invisible with this.visible = false;) to gain focus before the scan and then lose focus after, this would also solve my problem although a little more ad hoc.

Thank you in advance for the answers,

Kevin


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images