VB.NET: keypress not working correctly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • osku200
    New Member
    • Mar 2008
    • 2

    VB.NET: keypress not working correctly

    So i have a game where the objective is to dodge cubes falling from the top of the form so they don't collide with your cube on the bottom of the form. I'm using an array to detect keypresses and key realeases. Here's some code:

    Detection of key presses/key releases:

    Private Sub game_KeyDown(By Val sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles Me.KeyDown
    keyarray(e.KeyC ode) = True
    End Sub
    Private Sub game_KeyUp(ByVa l sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles Me.KeyUp
    keyarray(e.KeyC ode) = False
    End Sub

    Move players cube:

    If running = True Then
    If keyarray(39) = True Then
    player.Left -= speed
    End If
    If keyarray(37) = True Then
    player.Left -= speed
    End If

    The problem is that when you press left arrow(keycode 37) it moves left, but when you press right arrow(39) it moves left too! Even if you press right arrow first, it moves left.

    So, please help!
Working...