IF Keys
(i
) THEN ' If this Keys() index contains a non-false value? IF _KEYDOWN(Keys
(i
)) THEN ' Using _keydown on the stored code in Keys() PRINT Keys
(i
) ' Print the code, as we already saw PRINT 0 ' Prints a zero on the screen? Never saw this happen Keys(i) = 0 ' Sees the key is no longer down, clear the value
FOR j
= i
TO 9 ' Collapse the array, eliminating the cleared value Keys(j) = Keys(j + 1)
Keys(10) = 0 ' After collapsing, the last index should always be clear
keysdown = keysdown - 1 ' Decrement a counter of how many keys are pressed
i = i - 1 ' Decrement the for loop's counter, so next loop will continue at the same counter
k
= _KEYHIT ' Detect a keystroke? How are multiple keystrokes on the same frame detected by this? IF k
> 0 THEN ' A keystroke was detected ' PRINT k
IF Keys
(i
) = k
THEN EXIT FOR ' Don't add a duplicate keystroke to Keys() IF Keys
(i
) = 0 THEN keysdown
= keysdown
+ 1: Keys
(i
) = k:
EXIT FOR ' Found an empty index, add here and increment number of keys pressed ELSEIF k
< 0 THEN ' OK, I'm maybe gathering that "keyup" might have meant a key was released? FOR i
= 0 TO keysdown
' As before, collapse the array since a key was detected released? IF Keys
(i
) = -k
THEN 'clear the up key Keys(j) = Keys(j + 1)
Keys(10) = 0
keysdown = keysdown - 1