Classic Computer Magazine Archive COMPUTE! ISSUE 52 / SEPTEMBER 1984 / PAGE 10

TI CALL KEY

I recently acquired a TI-99/4A and wondered if you would explain the use of the CALL KEY command?

David Stinchcomb

The CALL KEY statement has caused confusion for many TI users. The KEY subprogram, designed to return a single keystroke value, requires three parameters: a key unit, a return variable, and a status variable. The statement takes the format:

CALL KEY (n,K,ST)

where n is the key unit, K is the return variable, and ST is the status variable.

The key unit used in the CALL KEY statement determines the keyboard configuration assumed by the computer. Six key unit values (0-5), or keyboard configurations, are available on the TI-99/4A. The three key units generally used are 0, 1, and 2. A key unit of 0 refers to the console keyboard. Key units 1 and 2 map the console keyboard as split keyboards (a value of 1 to read the left side of the keyboard, a value of 2 to read the right), or read the fire buttons on joystick 1 and 2, respectively.

When a CALL KEY statement is executed with a key pressed, some value will be assigned to K (in our example above). The value given to K will depend on the key pressed and the key unit used in the CALL KEY statement. If you use a key unit of zero, K will correspond to the ASCII value of the key being pressed. For other keyboard configurations, the value of K will vary as noted in the TI User's Reference Guide (pp. 11-87 to 11-89). Eighteen in K signifies that the fire button was pressed.

The final parameter used in the CALL KEY statement is the status variable (ST). A nonzero value returned for ST indicates that a key was being pressed when the CALL KEY statement was executed.

CALL KEY can be used to get a desired response from the program user. If you want to test for any keystroke (with key unit 0), you would use the following two lines:

10 CALL KEY(0, K, ST)
20 IF ST = 0 THEN 10

The program repeatedly loops back to line 10 until some key is pressed.

If you want the program to accept only a specific response from the user, such as Y for "yes," you could add these lines:

5 PRINT "TYPE THE Y KEY"
30 IF K<>89 THEN 10

Until the Y key is pressed, the program will loop back to 10.