Wait for Key
simple code to wait until a key is pressed

INKEY$ is just like a string variable where the system puts a string which consists on the keys that are in the buffer. If no key has been pressed, the buffer is empty and INKEY$="". When a key is pressed, whatever the key is (except CTRL, SHIFT and such) copied in ascii form to the INKEY$ variable. That way, INKEY$=something or, what it's the same INKEY$<>"".

Anyways, it is better to clear the buffer before. Y'know, imagine a long loop in your program. If you press a key, as it is not being read, it will remain in a buffer. If you have an IF INKEY$<>"" THEN ... sentence right after the buffer, that key will be read by INKEY$ and maybe that's not what you like. So it is better to do this:

WHILE INKEY$<>"":WEND   ' loops while the buffer is full.
WHILE INKEY$="":WEND ' waits for a new keypress.

Note the loops: The first one loops while there are keys pressed. That cleans the buffer. Then, the second one, loops while there aren't keys pressed, so it will exit when you press a key. Note that this is only applicable when you are just waiting for a keypress.

You don't need to use WEND or WHILE. You can do it with DO LOOP or even GOTO:
1 I$ = INKEY$: IF I$ = "" THEN GOTO 1

WaitForKey - page last edited 2004-01-22 13:03:10 by (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster