Results 1 to 4 of 4

Thread: get both down keys

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    If i am holding down both the Down arrow key and the z key, but they control different things, how can I tell if both are down?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    You can use GetASynchKeyState:

    Public Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Guest
    Use like:

    Code:
    Private Sub Timer1_Timer()
        
        If GetAsyncKeyState(vbKeyControl) Then
        If GetAsyncKeyState(vbKeyZ) Then
        MsgBox "ctrl+z"
        End If
        End If
    
    End Sub

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Getasynckeystate isn't nessesary if you use shift/ctrl/alt + a key.

    BTW, if you use getanynckeystate to get seval keypresses, put them in keydown event instead of a timer, that will save you some resources and performance.
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = 90 And Shift = 2 Then MsgBox "Ctrl-Z"
    End Sub
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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