VB.net keytraps help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bludawg
    New Member
    • Apr 2012
    • 1

    VB.net keytraps help

    Hi, I am using this to make the object 'Pos' move around the form which has buttons on it. When a button is pressed this stops working, is there anyway to stop this from happening, also using the arrow keys does not work and stops the wasd keys from working. I have tried enabling and disabling the buttons, but this doest work.

    Code:
        Private Sub trapKey(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
            
                If e.KeyData = Keys.S Or e.KeyData = Keys.Down Then
    
                    If Pos.Top < 675 Then
                        Pos.Top = Pos.Top + 5
                    End If
                    
                ElseIf e.KeyData = Keys.W Or e.KeyData = Keys.Up Then
    
                    If Pos.Top > 215 Then
                        Pos.Top = Pos.Top - 5
                    End If
    
                   
    
                ElseIf e.KeyData = Keys.A Or e.KeyData = Keys.Left Then
    
                    If Pos.Left > 20 Then
                        Pos.Left = Pos.Left - 5
                    End If
                   
    
                ElseIf e.KeyData = Keys.D Or e.KeyData = Keys.Right Then
    
                    If Pos.Left < 482 Then
                        Pos.Left = Pos.Left + 5
                    End If
                  
                End If
            
        End Sub
    Thanks
Working...