Jump to content
  • Advertisement
Sign in to follow this  
Dan Verssen

VB2005 Arrow Keys

This topic is 4074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a nice sub that looks for when the 4 arrow keys are pressed. I then use that info to programically click buttons (1 to 4) that the user would click to move a little figure around the screen. This way, the user can click the buttons, or use the arrow keys. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Up Then Button1.PerformClick() End If If e.KeyCode = Keys.Right Then Button2.PerformClick() End If If e.KeyCode = Keys.Down Then Button3.PerformClick() End If If e.KeyCode = Keys.Left Then Button4.PerformClick() End If End Sub The problem is, when I use the arrow keys, it cycles through the other controls on the form as if I were pressed the Tab key. I have tried turning off all their "Tabstops" and it does no good. Once the focus reaches a textbox, the arrow keys work fine, but until it reaches the textbox, the arrows do not move the figure on the screen. If I change the Keys commands to be regular keys, like an "A", it works perfect. How do I turn off the tabbing of the arrow keys?

Share this post


Link to post
Share on other sites
Advertisement
You need to override the form's Control.IsInputKey(Keys) method to return True when an arrow key is passed to it.

Protected Overrides Function IsInputKey(ByVal keyData As Keys) As Boolean
Select Case keyData
Case Keys.Up, Keys.Down, Keys.Right, Keys.Left
Return True
Case Else
Return MyBase.IsInputKey(keyData)
End Select
End Function


Apologies if the source is incorrect, I'm a C# programmer. [wink]

You might also have to set Form.KeyPreview to True.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!