
-----------------------------------
pavol
Tue Jan 03, 2006 11:33 am

input
-----------------------------------
i am using the keyboard to move an object accross the screen (directional buttons). this is the code i use to get input from the keyboard
Select Case vbKeyCode
    Case vbKeyUp
        'code for up

    Case vbKeyDown
        'code for down

....etc


this has its limits because you can't press two keys at once. ex, you can't press left and up and make the object go diagonally. this code is in the Form_KeyDown procedure, is there a solution using the code i have or will i have to use this kind of code in the Form_KeyPress procedure?
If KeyAscii = 'whatever Then
    'move object 
End If
or is that also not possible? i am lost :? 
any help is appreciated. thanks

-----------------------------------
HazySmoke)345
Tue Jan 03, 2006 5:43 pm


-----------------------------------
Try this for now (there might be a better solution): You need a Form1, a Label1, and a Timer1 with a nonzero interval (I used 50)

Const Up = 0
Const Down = 1
Const Left_ = 2
Const Right = 3

Dim KeyHeld(0 To 3) As Boolean

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyUp
            KeyHeld(Up) = True
        Case vbKeyDown
            KeyHeld(Down) = True
        Case vbKeyLeft
            KeyHeld(Left_) = True
        Case vbKeyRight
            KeyHeld(Right) = True
    End Select
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyUp
            KeyHeld(Up) = False
        Case vbKeyDown
            KeyHeld(Down) = False
        Case vbKeyLeft
            KeyHeld(Left_) = False
        Case vbKeyRight
            KeyHeld(Right) = False
    End Select
End Sub

Private Sub Timer1_Timer()
    If KeyHeld(Up) Then Label1.Top = Label1.Top - 50
    If KeyHeld(Down) Then Label1.Top = Label1.Top + 50
    If KeyHeld(Left_) Then Label1.Left = Label1.Left - 50
    If KeyHeld(Right) Then Label1.Left = Label1.Left + 50
End Sub

-----------------------------------
cool dude
Tue Jan 03, 2006 6:36 pm


-----------------------------------
the way that i would do it would be like this


Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 97 Then
        Shape1.Move Shape1.Left - 50, Shape1.Top - 50
    End If
End Sub


if u press "A" the ball will move diagonally. u could do this with any letter on the keyboard. to find out the keyascii for each letter in this form_keypress just type at the top print keyascii.  every time u press letter on keyboard it will tell u the number for keyascii.

-----------------------------------
HazySmoke)345
Wed Jan 04, 2006 10:32 am


-----------------------------------
There's something wrong with the keypress event: Notice that, when you're holding a key, this is what happens, let's say that you hit the key "A", the computer will display:

A two keys at a time, so key A wouldn't work that well, would it?

-----------------------------------
cool dude
Wed Jan 04, 2006 12:53 pm


-----------------------------------
wat do u mean the computer starts displaying A's it doesn't for me. anyways if pavol does want to make it work with holding two buttons then u could just add if keyaskii =97 and someother button. although about the smoothness your way is smoother  :)

-----------------------------------
pavol
Thu Jan 05, 2006 4:17 pm


-----------------------------------
thanks HazySmoke)345
