Have c# Windows Control ignore input

I have  Windows Application written in c# which displays a form full-screen divided into six equal segments.  Each segment has a combination of textbox, listbox, and button controls.  I have six wireless keyboards plugged into the machine and each keyboard controls one of the segments.

I have used the Raw Input example proviced on http://www.codeproject.com/KB/system/rawinput.aspx?fid=375378&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2834754&fr=1#xx0xx to capture keyboard events and forward to the appropriate segment on the screen.

The problem is focus.  If one of the controls has focus and a keyboard key is clicked the raw input gets forwarded to the control however the control also gets the input resulting in a duplicate keystroke being processed.  To illustrate, if a textbox has the focus and I click the letter A the textbox shows "AA".

I can't seem to figure this out property so I wondered if there is a way I could make this user control simply ignore input it received directly.

Thank you for any help!
Who is Participating?
canuckconsultingConnect With a Mentor Author Commented:
In the end I removed the messages using PeekMessage().  Please see this excellent article for details:

HainKurtSr. System AnalystCommented:
looks like there is a logic problem on your app... what are you doing after getting the key event... maybe you are adding a key and one is added automatically... do you have any code sample, it is very difficult (if not impossible) to suggest something w/o seeing any code...
canuckconsultingAuthor Commented:
Let's take the listbox as an example.  If I get a KeyUp event and the focus is on the listbox I have set my code to do nothing.  So I do not process the keystroke.  Despite this the keystroke is processed by the control itself and the selected item moves up.

Basically it seems like I can't flag the event as "handled" at the form level so the control gets it anyway!  I want my form to handle all keystrokes instead of the controls themselves dealing with them.
Mike TomlinsonMiddle School Assistant TeacherCommented:
I suggest you Implement IMessageFilter, which lets you "peek" at ALL messages intended for your entire app BEFORE they get routed to the current form/control.  You can suppress messages so they don't get routed at all.  It looks like your raw input code will trigger a WM_INPUT message.  Try filtering out the "regular" keystrokes by suppressing WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN and WM_SYSKEYUP.
canuckconsultingAuthor Commented:
Idle_Mind, I should have mentioned that when I implemented the IMessageFilter my Raw Inputs also ceased so my application was getting no events at all.  Thank you for taking the time to write!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.