: : : Sorry for bother you again, but I don't understand the code, I actually is a newbie, can you give me example. Thank you.
: : :
: :
: : Alright, let's start with this: What keys do you wish to watch for? And which keys must be combined?
: :
:
: I am try to do this program and test it, but it won't work like what I want, would you get a try. Thank you.
:
:
:
: Option Explicit
: Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
:
: Private Sub Form_Activate()
: Dim GameOver As Boolean
:
: Do
:
: If GetAsyncKeyState(vbKeyUp) < 0 Then
: Label1.Visible = True
: Else
: Label1.Visible = False
: End If
:
: If GetAsyncKeyState(vbKeyDown) < 0 Then
: Label2.Visible = True
: Else
: Label2.Visible = False
: End If
:
: If GetAsyncKeyState(vbKeyLeft) < 0 Then
: Label3.Visible = True
: Else
: Label3.Visible = False
: End If
:
: If GetAsyncKeyState(vbKeyRight) < 0 Then
: Label4.Visible = True
: Else
: Label4.Visible = False
: End If
:
: If GetAsyncKeyState(vbKeySpace) < 0 Then
: Label5.Visible = True
: Else
: Label5.Visible = False
: End If
: If GetAsyncKeyState(vbKeyEscape) < 0 Then GameOver = True
:
: DoEvents
:
: Loop Until GameOver = True
:
: End
: End Sub
:
:
:
:
: I am try to write a game. And I found it some key doesn't work like what I do. In this program, we can press Up, Down, Left, Right, and space key and it will appear what key we press. It is OK if I try to press up, right and space key, It will show Up, right and space key were pressing. But it won't work if I press Up, left and space. It only show Up and left key. There are some other key when I try to press 3 key in one times and it won't show up all the key. so, please help.
:
Odd... I have no idea why it won't work. All the code looks perfectly OK to me. While I can't fix your code, I can tell you that this version of it is faster, easier to read and won't be as likely to contribute to system crashes:
Private Sub Form_Activate()
Do Until GetAsyncKeyState(vbKeyEscape) < 0
Label1.Visible = CBool(GetAsyncKeyState(vbKeyUp) < 0)
Label2.Visible = CBool(GetAsyncKeyState(vbKeyDown) < 0)
Label3.Visible = CBool(GetAsyncKeyState(vbKeyLeft) < 0)
Label4.Visible = CBool(GetAsyncKeyState(vbKeyRight) < 0)
Label5.Visible = CBool(GetAsyncKeyState(vbKeySpace) < 0)
DoEvents
Loop
'End. NEVER use End. Unload all forms, set all objects to
'nothing and exit all code. App will end on it's own.
Unload Me
End Sub
I sincerely doubt my rewrite made a difference, but I tested my code and it detects all the keys properly.