INKEY

A function and compatible string function which does a GET/GET$, but waits for a specified maximum time rather than indefinitely. INKEY can also be used to test the current state of a specific key (pressed or not pressed).

INKEY or INKEY$ is followed by a numeric argument. If this is zero or positive it indicates the maximum time to wait for a keypress (in units of 10ms). If it is negative it indicates which key should be tested.

INKEY positive or zero argument

INKEY/INKEY$ waits for the specified maximum number of clock ticks of 10ms each. If no key is pressed in the time limit, INKEY will return -1 and INKEY$ will return a null (empty) string. If there is one or more characters waiting in the keyboard buffer, INKEY/INKEY$ will behave exactly the same as GET/GET$. If the specified time limit is zero, INKEY/INKEY$ will return immediately.

The INKEY function returns the ASCII value of the key pressed. The INKEY$ function returns a string (length=1) containing the character corresponding to the key pressed.

key=INKEY(num)
N=INKEY(0)
N$=INKEY$(100)

INKEY can be used to 'empty' the keyboard buffer. You can do this with the following program line:

REPEAT UNTIL INKEY(0)=-1

INKEY negative argument

If INKEY is followed by a negative argument, the state of a particular key is tested. If the key is currently pressed INKEY will return the value -1 (TRUE); if the key is not pressed INKEY will return the value 0 (FALSE).

The numeric values corresponding to the different keys are as follows (note that these values are as compatible as possible with the BBC Micro and the Acorn Archimedes, allowing for the differences between their keyboards and the PC's keyboard).

IF INKEY(-74) PRINT "Enter pressed"

INKEY(-256)

INKEY(-256) is a special case that can be used to identify the hardware. It will return &83 for a TI-83+(SE) and &84 for a TI-84+(SE).

Syntax

Associated Keywords