Link to home
Start Free TrialLog in
Avatar of canuckconsulting
canuckconsultingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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!
Avatar of HainKurt
HainKurt
Flag of Canada image

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...
Avatar of canuckconsulting

ASKER

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.
Avatar of Mike Tomlinson
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.
ASKER CERTIFIED SOLUTION
Avatar of canuckconsulting
canuckconsulting
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!