keyup, keydown,slowkeydown - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Utilities (https://staging.qb64phoenix.com/forumdisplay.php?fid=8) +---- Thread: keyup, keydown,slowkeydown (/showthread.php?tid=758) |
keyup, keydown,slowkeydown - James D Jarvis - 08-10-2022 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 RE: keyup, keydown,slowkeydown - SMcNeill - 08-11-2022 Just curious; you do know that we have a _KEYUP and _KEYDOWN set of commands? RE: keyup, keydown,slowkeydown - BSpinoza - 08-11-2022 (08-11-2022, 10:40 AM)SMcNeill Wrote: Just curious; you do know that we have a _KEYUP and _KEYDOWN set of commands? Can not find a _KEYUP command in Help or Wiki. RE: keyup, keydown,slowkeydown - James D Jarvis - 08-11-2022 (08-11-2022, 10:40 AM)SMcNeill Wrote: Just curious; you do know that we have a _KEYUP and _KEYDOWN set of commands? the keydown function I posted here returns any key pressed and in effect waits until a key is pressed so it isn't identical to the _keydown command, the _keydown command confirms if a specific key was pressed when polled. _keyup doesn't exist on the wiki and it isn't recognized by the version of the compiler I'm still using. RE: keyup, keydown,slowkeydown - bplus - 08-11-2022 Steve is always 2 steps ahead of us, he's probably talking about future developments :-)) _KEYUP(kh&) = NOT _KEYDOWN(kh&) RE: keyup, keydown,slowkeydown - SMcNeill - 08-11-2022 (08-11-2022, 03:42 PM)bplus Wrote: Steve is always 2 steps ahead of us, he's probably talking about future developments :-)) Actually, I was thinking we had some simple commands somewhere which only listed when keys went up and down. Apparently we don't and those were library functions which I'd written once. My apologies. For an example of what I'm talking about, try this little code: Code: (Select All) Dim Shared As Long KeyBuffer(10), KeyDownKey, KeyUpKey This *only* lists when a key goes down, or when a key comes up. No repeat messages from it! Just glancing over James's code, I saw the comment "only returns positive values when a key is pressed", so my brain was thinking it was working in a similar manner. What we have above is a set of routines which tells you *only* when a key is pressed down, or when a key is released. Of course, most keyboards only report 6 keys at a time or so, due to basic USB limitations, so if you want to go crazy and press a dozen keys down at once and hold them all, you'll probably end up glitching out the buffer here as I didn't write this little demo to deal with something that complex. RE: keyup, keydown,slowkeydown - SMcNeill - 08-11-2022 A quick little update to handle the keyboard overflow type issue. Note that if you press 7+ keys down, you won't get a report on any key being lifted up until after you release them down to no more than 6 actually being pressed. Keyboards have a natural limit of 6 keys that they can report on at a time, and if you flood them with extra presses, you end up making them not very happy! Code: (Select All) Dim Shared As Long KeyBuffer(10), KeyDownKey, KeyUpKey RE: keyup, keydown,slowkeydown - PhilOfPerth - 08-12-2022 Sorry Pete, but I think about the only place where this becomes relevant is when the cat sneaks in and sits on the keyboard! RE: keyup, keydown,slowkeydown - James D Jarvis - 08-12-2022 Oh I like. There's times when multi-key presses are desirable. |