Here's a problem I've had for some time. This is the section of my code which checks if the user presses a key, and moves a sprite along the map according to which button is pressed. If the user presses the "Numpad5" key, it switches on and off some text.
CODE
Case 5
info *= -1
(info is an integer I used as a substitute for a boolean, if info = 1 then it prints the text)
When I press Numpad5, the keyboard polls its own state so fast that if I hold the key down for even a moment the text flickers on and off really quickly.
Here is the code. With as little change as possible, how can I slow down the rate of the keyboard's poll?
CODE
Private Sub CheckInput()
Dim keynum As Integer
keyboard.Poll()
If movetile > 0 Then
If keyboard.KeyState(Key.NumPad1) Then keynum = 1
If keyboard.KeyState(Key.NumPad2) Then keynum = 2
If keyboard.KeyState(Key.NumPad3) Then keynum = 3
If keyboard.KeyState(Key.NumPad4) Then keynum = 4
If keyboard.KeyState(Key.NumPad5) Then keynum = 5
If keyboard.KeyState(Key.NumPad6) Then keynum = 6
If keyboard.KeyState(Key.NumPad7) Then keynum = 7
If keyboard.KeyState(Key.NumPad8) Then keynum = 8
If keyboard.KeyState(Key.NumPad9) Then keynum = 9
End If
Select Case keynum
Case 1
MoveSpriteY(spdy)
MoveSpriteX(-spdx)
movetile -= 1
Case 2
MoveSpriteY(spdy)
movetile -= 1
Case 3
MoveSpriteY(spdy)
MoveSpriteX(spdx)
movetile -= 1
Case 4
MoveSpriteX(-spdx)
movetile -= 1
Case 5
info *= -1
Case 6
MoveSpriteX(spdx)
movetile -= 1
Case 7
MoveSpriteY(-spdy)
MoveSpriteX(-spdx)
movetile -= 1
Case 8
MoveSpriteY(-spdy)
movetile -= 1
Case 9
MoveSpriteY(-spdy)
MoveSpriteX(spdx)
movetile -= 1
End Select
If keyboard.KeyState(Key.Escape) Then
keyboard = Nothing
mouse = Nothing
scroller = Nothing
sprite1 = Nothing
d3d = Nothing
clock.Stop()
Me.Close()
End If
End Sub
CheckInput is called in the main function, perhaps I need to alter the function call instead.
This isn't a homework assignment, so don't hold back! Any level of complexity is welcome. Thanks guys.