Results 1 to 3 of 3

Thread: Form_KeyPress having CommandButton with focus

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Albacete, Spain
    Posts
    71

    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

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Albacete, Spain
    Posts
    71

    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
  •  



Click Here to Expand Forum to Full Width