KEYTRAP statement
Syntax
KEYTRAP (value, key) [ , (value, key) ] ...
Description
Use the KEYTRAP statement to specify traps for the keys assigned specific functions by the KEYEDIT statement. When a trap key is typed, the variable being edited with the INPUT statement @ statement or the !EDIT.INPUT subroutine is restored to its initial state. Use the KEYEXIT statement to leave the variable in its last edited state.
value is an expression that evaluates to a user-defined trap number for each key assigned by the KEYEDIT statement.
key is a decimal value which designates the specific keyboard key assigned to the editing function. There are three key types, described in the following table:
| Type | Decimal Value | Description |
|---|---|---|
| Control | 1 through 31 | Single character control codes ASCII 1 through 31. |
| Escape | 32 through 159 | Consists of the characters defined by the Esc key followed by the ASCII value 0 through 127. |
| Function | 160 through 2,139,062,303 | Consists of the characters defined by the function key followed by the ASCII value 0 through 127. A maximum of four ASCII values might be specified for complex keys. |
See the KEYEDIT statement for how to derive the decimal value of control, escape, and function keys.
If either the value or key expression evaluates to the null value or an empty string, the KEYEXIT statement fails, the program terminates, and a run-time error message is produced.
KEYTRAP sets the STATUS function to the trap number of any trap key typed by the user.
Examples
The following example sets up Ctrl-B as a trap key. The STATUS function is set to 1 when the user types the key.
KEYTRAP (1, 2)
The next example defines function key values for the F1, F2, F3, and F4 keys on a Wyse 50 terminal:
KEYEDIT (1,1)
KEYTRAP (1,224), (2,225), (3,226), (4,227)
PRINT @(-1)
VALUE = "KEY"
INPUT @ (10,10):VALUE
X=STATUS()
BEGIN CASE
CASE X = 1
PRINT "FUNCTION KEY 1"
CASE X =2
PRINT "FUNCTION KEY 2"
CASE X =3
PRINT "FUNCTION KEY 3"
CASE X =4
PRINT "FUNCTION KEY 4"
END CASE
PRINT VALUE
STOP
END