Scalextric car model - capturing arrow key presses 
Author Message
 Scalextric car model - capturing arrow key presses

Hi I am making a kind of scalextric model in VB .NET and want to capture the
arrow keys so when someone presses up, the car moves up for example. (I'm
starting crude and building it up)

Problem is when the form loads and i press an arrow key it simply moves
focus to the controls on the form such as a command button i have.
The form KeyPreview property is set to true and the other form controls have
false TabStop properties.

The code to handle the arrow presses is shown here:

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    Select Case e.KeyCode
        Case Keys.Left
            CtrlCar1.moveCar(2, Val(txtDisplacement.Text))
        Case Keys.Right
            CtrlCar1.moveCar(3, Val(txtDisplacement.Text))
        Case Keys.Up
            CtrlCar1.moveCar(1, Val(txtDisplacement.Text))
        Case Keys.Down
            CtrlCar1.moveCar(4, Val(txtDisplacement.Text))
    End Select
    e.Handled = True
End Sub

Would i be better checking in a timer event for keypresses and if so what
frequency timer do you suggest. (I am imagining a user holding down a key to
move the car and letting go to slow down)

I appreciate any help
Cheers
Matt
--
================================
Remove NOSPAM to reply to my address



Sat, 23 Jul 2005 10:17:37 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Capture arrow key press when an option group has the focus

2. Trap cursor/arrow key presses

3. Detecting Keypress if Arrow Keys are pressed

4. ****Getting a Sprite To Move When You Press An Arrow Key****

5. Model DialogBox is hideing behind main application after pressing ALT+ESC keys

6. Capturing arrow key events for labels

7. capturing arrow keys in listview control

8. Capturing Arrow Keys when Focus is Set to a Command Button

9. MSFlexGrid - Capturing Arrow keys

10. How capture arrow keys from a MsFlexGrid

11. How do I capture Arrow keys

12. How do I capture Arrow Keys?

 

 
Powered by phpBB® Forum Software