Have c# Windows Control ignore input

Posted on 2009-12-22
Last Modified: 2013-12-17
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 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!
Question by:canuckconsulting
    LVL 51

    Expert Comment

    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...

    Author Comment

    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.
    LVL 85

    Expert Comment

    by: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.

    Accepted Solution

    In the end I removed the messages using PeekMessage().  Please see this excellent article for details:

    Author Comment

    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!

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now