Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Last active December 10, 2015 18:29
Show Gist options
  • Save ryasmi/4475357 to your computer and use it in GitHub Desktop.
Save ryasmi/4475357 to your computer and use it in GitHub Desktop.
Handling multiple key presses in Visual Basic. Useful for controls in games and shortcut keys. Based on my YouTube tutorial (http://www.youtube.com/watch?v=G6ZbQ1kpAtQ&list=PL63C2673281C99172&index=4).
' Tutorial @ http://www.youtube.com/watch?v=G6ZbQ1kpAtQ&list=PL63C2673281C99172&index=4
Private Sub _KeyDown(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.W Then
Label1.Text = "W Pressed"
End If
If e.KeyValue = Keys.S Then
Label2.Text = "S Pressed"
End If
End Sub
Private Sub _KeyUp(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If e.KeyValue = Keys.W Then
Label1.Text = "W Not Pressed"
End If
If e.KeyValue = Keys.S Then
Label2.Text = "S Not Pressed"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment