Format: var = KEY
Supported by: Telmac SBASIC v 24.3, Pecom 32 BASIC, Pecom 64 BASIC 1.0 and 4.0
This function returns the ASCII code of a key pressed. Its use may be illustrated by the following example.
When the function KEY is encountered, the keyboard is scanned, and the. ASCII code of the key pressed is returned. If this is equal to 65 (which is the ASCII decimal code for key A), the message "KEY A PRESSED" is printed, and the program is terminated. If any key other than key A is pressed, the program goes round a loop, scanning the keyboard repeatedly.
The above program illustrates the typical situation the function KEY is used. It is most often used in an "IF-statement" located within a loop, such that the keyboard is scanned repeatedly, and certain action will be taken if a specified key is pressed. This enables the pressing of the specified key to control the flow of a program.
Note: the following information may become useful for a more detailed understanding of the KEY function. When a key is pressed, its ASCII code is sent to a register or latch. Functions like KEY (or INPUT) will read the content of this latch, and then clear the latch. If no key is pressed, KEY will return the value 0.