08-11-2022, 04:53 PM
(08-11-2022, 03:42 PM)bplus Wrote: Steve is always 2 steps ahead of us, he's probably talking about future developments :-))
_KEYUP(kh&) = NOT _KEYDOWN(kh&)
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
UpdateKeys = _FreeTimer
On Timer(UpdateKeys, .01) CheckKeys
Timer(UpdateKeys) On
Do
kd = KeyOnlyDown
ku = KeyOnlyup
If kd Then Print "Key"; kd; "Pressed down"
If ku Then Print "Key"; ku; "Released"
_Limit 30
Loop
Sub CheckKeys
K = _KeyHit
Select Case K
Case Is < 0 'keyup
For i = 0 To 10
If KeyBuffer(i) = Abs(K) Then KeyUpKey = Abs(K): KeyBuffer(i) = 0
Next
Case Is > 0 'keydown
For i = 0 To 10
If KeyBuffer(i) = Abs(K) Then Exit For
Next
If i > 10 Then
For i = 0 To 10
If KeyBuffer(i) = 0 Then KeyBuffer(i) = Abs(K): KeyDownKey = Abs(K): Exit Sub
Next
End If
End Select
End Sub
Function KeyOnlyDown&
If KeyDownKey <> 0 Then KeyOnlyDown = KeyDownKey: KeyDownKey = 0
End Function
Function KeyOnlyup&
If KeyUpKey <> 0 Then KeyOnlyup = KeyUpKey: KeyUpKey = 0
End Function
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.