0

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

Saturn
  • 17,888
  • 49
  • 145
  • 271
  • Um, how about [binding a keydown listener](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx)? – Matt Ball Apr 06 '11 at 23:41
  • possible duplicate of [How do I know if a arrow key was pressed and not released?](http://stackoverflow.com/questions/4469939/how-do-i-know-if-a-arrow-key-was-pressed-and-not-released) – Hans Passant Apr 07 '11 at 00:13
  • Read this http://stackoverflow.com/questions/5589130/check-if-delete-key-is-pressed/7527570#7527570 – Hungry Mind Sep 23 '11 at 10:30
  • Which language is this question about? ‍♂️ – Scott Jul 26 '22 at 11:05
  • @Scott are the tags not loading for you? They clearly say [vb.net] – Saturn Jul 26 '22 at 22:11
  • @Saturn, yeah, they are not loading for me – Scott Jul 27 '22 at 01:10
  • @Scott ah, I see. Well at least you can tell from the answer that it's clearly VB.NET, but I guess maybe not even answers are loading for you – Saturn Jul 27 '22 at 09:21

1 Answers1

1

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
SwissGuy
  • 565
  • 1
  • 6
  • 18