|
-
Aug 10th, 2005, 04:48 PM
#1
Thread Starter
Lively Member
Form_KeyPress having CommandButton with focus
Hi. As most of you know, we can enable the form to get all the keyboard events by setting its KeyPreview property to True. But if we have a CommandButton with the focus and we press the Enter key, we'll get a Command1_Click event instead of the Form_KeyPress. The same occurs if we press the arrow keys , when the focus belongs to a ListBox control... do you know if there is any workaround to do make the Form_KeyPress be fired event in these cases?
Thank you guys
-
Aug 10th, 2005, 05:07 PM
#2
Re: Form_KeyPress having CommandButton with focus
I'm thinking that the GetAsyncKeyState API or DirectInput might help bypass this problem since it retrieves input directly from the keyboard rather than through window messages, even if the form is not in focus and another app is.
-
Aug 10th, 2005, 05:17 PM
#3
Thread Starter
Lively Member
Re: Form_KeyPress having CommandButton with focus
Well, that sounds good. But I don't know if that will work. I'll explain why: It's not a keyboard what I'm using, but a scanner. That scanner simulates the keyboard input and sends a pair 13-10 (vbCrLf) afterwards.
For example, let's imagine I read a barcode with my scanner. I'll get one Form_KeyPress event for each number in my barcode. After all these numbers in the bar code, the scanner sends a vbCrLf, which is handled as if the user had pressed the Enter key: the focused CommandButton fires a Click event, and the Form_KeyPress doesn't trigger.
I'll try the GetAsyncKeyState approach, and tell you what happened.
Thanks for your input!
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
|