PDA

Click to See Complete Forum and Search --> : Multiple Key presses


paolo
Nov 15th, 1999, 06:38 PM
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.

Geoff Gunson
Nov 15th, 1999, 08:29 PM
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

MartinLiss
Nov 15th, 1999, 08:35 PM
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:
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