|
-
Aug 16th, 2006, 07:10 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Handling all KeyDowns?
Hi all,
is there a way to listen for keydown events on all controls at the same time? I am capturing a barcode scanner's input and the scanner is hooked to a pc. On barcode lock, it simply pastes the number. This means that whatever control currently has the focus, gets also the number.
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
'MessageBox.Show(e.KeyValue.ToString) helped me to get the keycode
txtBarcode.Focus()
End Sub
This works but only if the form itself has the focus. Do I have to check the keydown event of every control or is there an event that fires each time, regardless of where the focus is.
I guess I could use ZaNi's idea but would it be at all sane with 50+ controls?
-
Aug 16th, 2006, 07:17 PM
#2
Fanatic Member
Re: Handling all KeyDowns?
Create a general Key_Down Event and attach it to all your controls upon creations? Do you manually associate events in VB.Net like in C#?
Use API and track all window messages, catch the keys your looking for, figure out the handle of the window that triggered the event.
-
Aug 16th, 2006, 07:26 PM
#3
Re: Handling all KeyDowns?
If you've set the form's KeyPreview property to True then it will receive keyboard events first regardless of which control has focus.
-
Aug 16th, 2006, 07:30 PM
#4
Fanatic Member
Re: Handling all KeyDowns?
I like the above post, much simpler
-
Aug 16th, 2006, 09:23 PM
#5
Thread Starter
Frenzied Member
Re: Handling all KeyDowns?
Jup, jmcilhinney is great. Still, I will have to investigate your suggestion as well, since the Compact Framework does not offer the KeyPreview property and I have to take care of that on mobile devices too.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|