11-23-2022, 02:49 AM
(11-23-2022, 02:42 AM)SMcNeill Wrote: Limit placement looks fine to me -- it's in your innermost loop, and the one where the user is going to interact with the most.
From what I see, after I restructured the code to get rid of the GOTOs, you might want to move the _KEYCLEAR however.
Code: (Select All)Print "hit a key"
Do
_KeyClear ' clear the buffer before looking for any new keystrokes
Do
_Limit 30 ' limit resource usage
k = _KeyHit ' get code of key press
Locate 12, 40: Print k; Space$(5) ' erase previous key code
Loop Until k > 0 ' if there are no keys pressed, have another look - but only do this max 30 times per second
Locate 13, 1: Print Space$(13); ' erase previous key code announcement
Locate 13, 1: Print "ok, saw"; k ' announce key that was recognized
Loop Until k = 27 ' look for another key press (exit with ESC)
For this short of an example, I'd think the above is what you want. Just ask yourself, "Do I want to process current key hits, or hits off the keyboard buffer?" Here, it appears you're just wanting to print the code for current key hits -- thus the _KEYCLEAR before the _KEYHIT loop. If you're wanting to check the whole buffer and process it however, you'd probably want that _KEYCLEAR outside the main loop completely, and between the PRINT and the DO statement in the code above.
Thanks Steve. I think I get it, I'll go play some more.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/