INKEY$

Function

INKEY$ reads the keyboard and returns a single character if an input is pending on the keyboard.

Syntax

A$ = INKEY$

Example

10 A$ = INKEY$
20 IF A$ = "" THEN 40
30 PRINT A$
40 GOTO 10

Remarks

If a key has not been pressed then a null string is returned. The ASCII code of each key, including control codes, is read and assigned to the one character string variable A$.

The characters entered into the program in this manner are not displayed on the screen unless explicitly printed (line 30 in the example). One application may be to insert a pause in a program before displaying another screen of information:

80 PRINT"last line of last screen"
90 A$=INKEY$: IF A$="" then 90
100 PRINT"First line of next screen"

If a function key is pressed then a two character string is returned consisting of the character ‘^’ and the number of the key pressed i.e. Pressing Function Key 1 will return the string “^1” to an INKEY$ function.