Just like INKEY$ has an input buffer, _KEYHIT does as well.
DO
LOCATE 1,1
PRINT INKEY$
PRINT INKEY$
PRINT INKEY$
PRINT INKEY$
PRINT INKEY$
LOOP UNTIL INKEY$ <> “”
Run the above, press the ASDF keys in order. Chances are, they’ll be read in the first INKEY$ statement and never in the 2nd to 5th. Your loop is processing the keys as fast as you’re hitting them, keeping the buffer clear.
Now, add a _DELAY 5 after the DO and run it. You’ll have time to put all 4 key presses into the buffer, and they’ll be cleared in a single pass with the multiple INKEY$ statements.
Press a key, it goes onto the buffer. Try this:
_DELAY 5
FOR I = 1 TO 10
PRINT INKEY$
NEXT
While the delay is active, press all sorts of keys — they all go onto the INKEY$ buffer. Quit hitting the keys before the 5 second delay is finished, and watch the FOR loop print your first 10 key presses, as it clears them from the buffer.
So, how’s this relate to what’s going on in your code??
Let’s run the program and hit the ASDF keys in order, and put them into the KEYHIT buffer...
When you get to the PRINT _KEYHIT, it’ll take the “A” off the buffer and print 65.
The “IF _KEYHIT = BN” will then pull the “S” from the buffer...
The “IF _KEYHIT = Ln” then pulls the “D” from the buffer...
*EACH* time INKEY$ is called, it pulls from the INKEY$ buffer, and *EACH* time _KEYHIT is called, it pulls from the _KEYHIT buffer...
So, if you only hit one key every loop cycle, it’d enter the buffer and get cleared with the PRINT _KEYHIT statement, clearing the buffer so the 2 IF statements will *always* be false. The only way you’d print “N” is if the 2nd character in the buffer = BN, and the only way you’ll print “n” is if the 3rd character in the buffer = 110...
To make it work correctly, read one character from the buffer at a time and process it a character at a time, as you are in your “code 2”.