Click to See Complete Forum and Search --> : VB 6.0, KeyUp,KeyDown, Problems


ant2334gog
April 16th, 2001, 04:32 PM
Is there any way to have something happen(let's say a car go forward) only while the up key is down. I was wondering this because I was making a drag racing game and I only want the car to go forward when the up key is down. Right now how I have it is you press the up key and the car keeps on going(I don't want that to happen). I tried the KeyUp command to fix this little problem but it doesn't work.

The code is below,

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp And d = False And c = True And g = True Then
If Form3.Label8.Caption = "Up" Then
Timer5.Enabled = True
Shape1.BackColor = vbGreen
End If
End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp And d = False And c = True And a = True And g = True Then
If Form3.Label8.Caption = "Up" Then
Timer5.Enabled = False
Shape1.BackColor = vbRed
End If
End If
End Sub

TipTap
April 16th, 2001, 06:19 PM
It should be reasonably easy... something like

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp then MoveCarFoward = True
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp then MoveCarFoward = False
End Sub

Then have another sub that checks the state of MoveCarFoward every x seconds and responds accordingly.

If I've missed the point, or missed something out, let me know.

Lee

ant2334gog
April 16th, 2001, 09:04 PM
No more help needed(on this topic)