Results 1 to 3 of 3

Thread: Multiple Key presses

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 1999
    Location
    ITALY
    Posts
    12

    Post

    How I can know when the user of my VB application press more than one letter on the keyboard ( combination like the letter "a" and the letter "c" pressed at the same moment)? Any suggestion will be appreciated.
    Thanks.


  2. #2
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241

    Post

    What you can use is the API function

    GetAsyncKeyState

    IE

    If GetAsyncKeyState(VK_DOWN) <> 0 Then (user pressed down)

    You could poll in a timer all the keys that you are interested in.

    See the Lander game demo from this site for example code.

    HTH

    Geoff

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Well, the computer can not actually do two things at once (like processing two inputs), but in any case, you can limit the user to one key press at a time and/or validate that input by putting code like the following in the KeyPress event:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    
        Dim sChar As String
        
        sChar = Chr(KeyAscii)
        
        Select Case UCase(sChar)
            Case "A", "B", "C"
                MsgBox "I'm OK"
            Case Else
                KeyAscii = 0
                MsgBox "I'm Not Valid"
        End Select
    
    End Sub
    The above restricts the user to entering A, B or C in either upper or lower case.

    ------------------
    Marty

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