-
Using Form_KeyDown?
I'm trying to make the arrow keys usable in a game I am writing in VB.NET
Here's a snippet of my code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
yy = yy - 1
drawit()
....
I can't get this to work, when I push the 'right' arrow key, the focus cycles between the form objects, moving from button to button, instead of executing this command here. How do I do this?
-
Re: Using Form_KeyDown?
You need to set the KeyPreview property of the form to true.
-
Re: Using Form_KeyDown?
I tried this, it didn't change anything.
-
Re: Using Form_KeyDown?
Try putting e.Handled = True in there
-
Re: Using Form_KeyDown?
That didn't work either. The focus just keeps jumping around the buttons when I push the arrow keys.
-
Re: Using Form_KeyDown?
Odd - it worked when I changed it to Keys.S, instead of the Arrow keys.
I'll go with WASD. Thanks.