Results 1 to 9 of 9

Thread: Keys

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Hiyas,

    How do I go about detecting if more than one key is pressed than once ? I'm making a game here and I just realised this... hehe. =)

    -Git

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Public x As Integer
    
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    'a has been pressed x amount of times
    If KeyAscii = 97 Then x = 1
      
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Actually I mean say if you're using the cursor keys, and you hold down two at once.

  4. #4
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Smile

    This is quite easy cos I am doing the same thing but I am only using one curosr key at a time. This is like the code I used: ( it might help)


    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Const VK_DOWN = &H28
    Private Const VK_LEFT = &H25

    If GetAsyncKeyState(VK_DOWN) <> 0 and GetAsyncKeyState(VK_LEFT) <> 0 Then


    End If

    if you have any trouble with this code then email me and I will sort it out. Or if you want I will send you the source code for my game. E-mail to [email protected]
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5
    Guest
    Use GetAsyncKeyState API.
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        If GetAsyncKeyState(vbKeyA) And GetAsyncKeyState(vbKeyB) Then MsgBox ("Both A and B were pressed at the same time")
    End Sub

  6. #6
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Oh yea I forgot to put the code in a timer
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Cool, I'll try it later. Thanks everyone. =)

  8. #8
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Just to make sure u know its only the If...Then That goes in the Timer


    Could you help me by going to my form. Thanx
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  9. #9
    Guest
    Also, the constants VK_DOWN, VK_LEFT etc. are already defined in VB as vbKeyDown and vbKeyLeft so you don't need to add them.

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