08-10-2022, 09:04 PM
(This post was last modified: 08-10-2022, 09:05 PM by James D Jarvis.)
Three little functions to help in using _keyhit for user input.
keyup only returns the release of a key
keydown only returns key presses and doesn't return negative values when a key is released.
Slowkeydown throttles how quickly entries are returned while holding down a key.
keyup only returns the release of a key
keydown only returns key presses and doesn't return negative values when a key is released.
Slowkeydown throttles how quickly entries are returned while holding down a key.
Code: (Select All)
_ControlChr Off
Print "press any key, <ESC> to exit"
Do
'edit the comments to see the differences in behavior
' k = keydown
k = keyup
' k = slowkeydown(5)
_KeyClear
Print k 'just the key hit value
If Abs(k) > 0 And Abs(k) < 256 Then Print Chr$(Abs(k)) 'show the ascii value of the key press if it has one
_Limit 60
Loop Until Abs(k) = 27
Function keyup
'only returns negative values when a key is released
'this will keep user from entering mutiple keypresses
Do
k = _KeyHit
_Limit 60
Loop Until k < 0
keyup = k
End Function
Function keydown
'only returns positive values when a key is pressed
Do
k = _KeyHit
_Limit 60
Loop Until k > 0
keydown = k
End Function
Function slowkeydown (r)
'returns positive vlaues when a key is pressed
'the variable r sets the frequency of the do loop , 60 would match the other functions here
'it wouldn't be slow at all if r had a high value but i didn't want to call it speedkeydown or ratekeydown
'this allows for continuous presses if a key is held down but not at machinegun rates
Do
k = _KeyHit
_Limit r
Loop Until k > 0
slowkeydown = k
End Function