|
-
Mar 21st, 2013, 01:03 PM
#1
Thread Starter
PowerPoster
[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)?
-
Mar 22nd, 2013, 01:20 PM
#2
Re: [keyboard] - what key selected and if was keydown or keyup
 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:
 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
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Apr 12th, 2013, 12:14 PM
#3
Junior Member
Re: [keyboard] - what key selected and if was keydown or keyup
 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???
-
Apr 12th, 2013, 12:37 PM
#4
Thread Starter
PowerPoster
Re: [keyboard] - what key selected and if was keydown or keyup
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|