keyup, keydown,slowkeydown
#1
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.


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
Reply


Messages In This Thread
keyup, keydown,slowkeydown - by James D Jarvis - 08-10-2022, 09:04 PM
RE: keyup, keydown,slowkeydown - by SMcNeill - 08-11-2022, 10:40 AM
RE: keyup, keydown,slowkeydown - by BSpinoza - 08-11-2022, 01:06 PM
RE: keyup, keydown,slowkeydown - by bplus - 08-11-2022, 03:42 PM
RE: keyup, keydown,slowkeydown - by SMcNeill - 08-11-2022, 04:53 PM
RE: keyup, keydown,slowkeydown - by SMcNeill - 08-11-2022, 04:56 PM
RE: keyup, keydown,slowkeydown - by PhilOfPerth - 08-12-2022, 11:01 AM



Users browsing this thread: 3 Guest(s)