Results 1 to 4 of 4

Thread: Key press - event

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    jerusalem
    Posts
    72

    Unhappy Key press - event

    I have a strange problem.
    I tried to test the "Key press - event" for several objects:
    commandButton,label,textbox...
    The problem is that the event returned (by msgbox) the KeyAscii
    each time when I clicked on the keyboard, except from the tab key.
    Why?
    Thank you

  2. #2
    Matthew Gates
    Guest
    Does this work for you?


    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyTab Then MsgBox "Tab pressed"
    End Sub
    
    Private Sub Form_Load()
        Me.KeyPreview = True
    End Sub

  3. #3
    sunnyl
    Guest
    Because that is that the KeyPress event returns. It returns the ASCII code for the key.

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    To convert the ASCII code to something useful:

    Code:
    MsgBox Chr(KeyAscii)
    The TAB key should be 9. Remember to set the Form's KeyPreview property to True.

  4. #4
    ok, a label doesn't have a keypress event, and the reason keypress isn't fired by tab is because it is setting the focus to some other control in the tabindex before it can fire for the current control and I have no clue why it doesn't fire on the control that it sets focus to though.
    Matt Bradbury

    An optimist will claim the glass is half full.
    A pessimist that it is half empty.
    I just think the glass is too big.

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