10-02-2022, 02:00 AM
If you want a reliable delay, don't use SLEEP. A key press interrupts SLEEP. Code SLEEP 60, run the program, and as soon as you press a key the sleep cycle is broken. _DELAT1 will always give a 1-second delay.
Another neat trick is to not delay the rest of the program at all, just delay the next key input...
I took out the CLS, so you could see the key progression. Easier to debug it that way. Lose the _KEYCLEAR if you want to peck away at the keyboard and have each key counted. If it is just about holding keys down, it's better to keep it.
My guess is you are looking for a way to move an RPG character up/down/right/left/and diagonal.
You will have to determine what, if any flags you need to set. For instance, right now a user can press three or more control keys.
Pete
Another neat trick is to not delay the rest of the program at all, just delay the next key input...
Code: (Select All)
PRINT "Press any single or combo of cursor arrow keys...": PRINT
DO
_LIMIT 30
IF TIMER - z1 > .5 THEN
ky = _KEYHIT
IF ky THEN
SELECT CASE ky
CASE IS = 18432 ' Up-arrow
IF _KEYDOWN(19200) THEN
PRINT "Up-arrow and Left-arrow"
ELSEIF _KEYDOWN(19712) THEN
PRINT "Up-arrow and Right-arrow"
ELSE PRINT "Up-arrow"
END IF
CASE IS = 19200 ' Left-arrow
IF _KEYDOWN(18432) THEN
PRINT "Left-arrow and Up-arrow"
ELSEIF _KEYDOWN(20480) THEN
PRINT "left-arrow and Down-arrow"
ELSE PRINT "Left-arrow"
END IF
CASE IS = 19712 ' Right-arrow
IF _KEYDOWN(18432) THEN
PRINT "Right-arrow and Up-arrow"
ELSEIF _KEYDOWN(20480) THEN
PRINT "Right-arrow and Down-arrow"
ELSE PRINT "Right-arrow"
END IF
CASE IS = 20480 ' Down-arrow
IF _KEYDOWN(19200) THEN
PRINT "Down-arrow and Left-arrow"
ELSEIF _KEYDOWN(19712) THEN
PRINT "Down-arrow and Right-arrow"
ELSE PRINT "Down-arrow"
END IF
END SELECT
_KEYCLEAR ' Remove this if you want each key pressed to register.
z1 = TIMER
END IF
ELSE
IF TIMER < z1 THEN z1 = z1 - 86400 ' Midnight adjustment.
END IF
LOOP
I took out the CLS, so you could see the key progression. Easier to debug it that way. Lose the _KEYCLEAR if you want to peck away at the keyboard and have each key counted. If it is just about holding keys down, it's better to keep it.
My guess is you are looking for a way to move an RPG character up/down/right/left/and diagonal.
You will have to determine what, if any flags you need to set. For instance, right now a user can press three or more control keys.
Pete