Results 1 to 4 of 4

Thread: [keyboard] - what key selected and if was keydown or keyup

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    [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)?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [keyboard] - what key selected and if was keydown or keyup

    Quote Originally Posted by joaquim View Post
    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
    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)

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    23

    Re: [keyboard] - what key selected and if was keydown or keyup

    Quote Originally Posted by Bonnie West View Post
    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???

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [keyboard] - what key selected and if was keydown or keyup

    Quote Originally Posted by affan546 View Post
    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width