Saturn
Saturn

Reputation: 18149

Check when arrow keys are pressed?

How can I check if an arrow key (dunno, the right key for example) is pressed?

Upvotes: 0

Views: 3124

Answers (1)

SwissGuy
SwissGuy

Reputation: 565

Just set the KeyPreview Property to true on Form load

after that you can use the KeyDown / KeyPress event.

    Private Sub main_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    '40 = ArrowkeyDown 38= ArrowKeyUp
    If Not e.KeyValue = 40 AndAlso Not e.KeyValue = 38 Then Exit Sub
    'Key Down / Up Code
End Sub

Upvotes: 1

Related Questions