[keyboard] - what key selected and if was keydown or keyup
the GetAsyncKeyState() function can detect if the keys still pressed(keydown) or was lefted(keyup)?
Re: [keyboard] - what key selected and if was keydown or keyup
Quote:
Originally Posted by
joaquim
the GetAsyncKeyState() function can detect if the keys still pressed(keydown) or was lefted(keyup)?
Yes. The description of the GetAsyncKeyState function says:
Quote:
Originally Posted by MSDN
Determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
I usually define a couple of constants so I can call GetAsyncKeyState like this:
Code:
Private Const KEY_DOWN As Integer = &H8000 'If the most significant bit is set, the key is down
Private Const KEY_PRESSED As Integer = &H1 'If the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As KeyCodeConstants) As Integer
Private Sub Timer1_Timer()
If (GetAsyncKeyState(vbKeyEscape) And KEY_DOWN) = KEY_DOWN Then
'The Escape key was pressed
Else
'The Escape key isn't being pressed
End If
End Sub
Re: [keyboard] - what key selected and if was keydown or keyup
Quote:
Originally Posted by
Bonnie West
Yes. The description of the
GetAsyncKeyState function says:
I usually define a couple of constants so I can call GetAsyncKeyState like this:
Code:
Private Const KEY_DOWN As Integer = &H8000 'If the most significant bit is set, the key is down
Private Const KEY_PRESSED As Integer = &H1 'If the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As KeyCodeConstants) As Integer
Private Sub Timer1_Timer()
If (GetAsyncKeyState(vbKeyEscape) And KEY_DOWN) = KEY_DOWN Then
'The Escape key was pressed
Else
'The Escape key isn't being pressed
End If
End Sub
sorry to ask as i am noob that what is the purpose of the above code???
Re: [keyboard] - what key selected and if was keydown or keyup
Quote:
Originally Posted by
affan546
sorry to ask as i am noob that what is the purpose of the above code???
is for testing if the ESC key is pressed(keydown) or release(keyup), but using a timer;)