VB 6.0, KeyUp,KeyDown, Problems
Results 1 to 3 of 3

Thread: VB 6.0, KeyUp,KeyDown, Problems

  1. #1
    Registered User
    Join Date
    Apr 2001
    Posts
    21

    Question VB 6.0, KeyUp,KeyDown, Problems

    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

  2. #2
    Member
    Join Date
    Feb 2001
    Location
    Luton, Bedfordshire, England
    Posts
    5

    Post

    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

  3. #3
    Registered User
    Join Date
    Apr 2001
    Posts
    21

    Thumbs up

    No more help needed(on this topic)

Bookmarks

Posting Permissions

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