Public Group

# VB2005 Arrow Keys

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

## 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 on other sites
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 SelectEnd Function

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

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

Thank you!

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633654
• Total Posts
3013168
×