INKEY$
Returns the character (or scan code, for control/special keys) immediatelly available in the keyboard buffer, without blocking
Implemented by: msatari, level2, trscolor, colormc, zx81, spectrum, BBC, GWBASIC, MSX, bwbasic, bw32, QBasic, VBDOS, minibasicjs
With variations:
Also written as:
Usage
INKEY$ will not stop and wait for the user to type something. If there is not a pressed key or a character in the keyboard buffer, it just returns nothing and goes away. Because of that, the most common way to use it was something like:
240 K$=INKEY$:IF K$ = "" THEN 240
It was no big deal in the 8-bit era when the BASIC program was the only thing running at the machine, but in more modern multitasking systems this will often sky-rocket CPU usage and make everything slow. It is necessary to give up some time for the system during the loop — some milliseconds per iteration is enough.
Variations
Examples
Comments
Related keywords
Similar keywords
In other languages...
In many modern languages, it is surprisingly difficult to have something like INKEY$ for input in a text-mode application. In C, the hairy ncurses library is probably the most used option.