Hiyas,
How do I go about detecting if more than one key is pressed than once ? I'm making a game here and I just realised this... hehe. =)
-Git
Printable View
Hiyas,
How do I go about detecting if more than one key is pressed than once ? I'm making a game here and I just realised this... hehe. =)
-Git
Code:Option Explicit
Public x As Integer
Private Sub Text1_KeyPress(KeyAscii As Integer)
'a has been pressed x amount of times
If KeyAscii = 97 Then x = 1
End Sub
Actually I mean say if you're using the cursor keys, and you hold down two at once.
This is quite easy cos I am doing the same thing but I am only using one curosr key at a time. This is like the code I used: ( it might help)
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_DOWN = &H28
Private Const VK_LEFT = &H25
If GetAsyncKeyState(VK_DOWN) <> 0 and GetAsyncKeyState(VK_LEFT) <> 0 Then
End If
if you have any trouble with this code then email me and I will sort it out. Or if you want I will send you the source code for my game. E-mail to [email protected]
Use GetAsyncKeyState API.
Code:Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyA) And GetAsyncKeyState(vbKeyB) Then MsgBox ("Both A and B were pressed at the same time")
End Sub
Oh yea I forgot to put the code in a timer
Cool, I'll try it later. Thanks everyone. =)
Just to make sure u know its only the If...Then That goes in the Timer
Could you help me by going to my form. Thanx
Also, the constants VK_DOWN, VK_LEFT etc. are already defined in VB as vbKeyDown and vbKeyLeft so you don't need to add them.