[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Have c# Windows Control ignore input

Posted on 2009-12-22
5
Medium Priority
?
890 Views
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 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!
0
Comment
Question by:canuckconsulting
  • 3
5 Comments
 
LVL 61

Expert Comment

by:HainKurt
ID: 26106063
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...
0
 

Author Comment

by:canuckconsulting
ID: 26106225
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26106385
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.
0
 

Accepted Solution

by:
canuckconsulting earned 0 total points
ID: 26108098
In the end I removed the messages using PeekMessage().  Please see this excellent article for details:

http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/
0
 

Author Comment

by:canuckconsulting
ID: 26108114
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!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 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