Top  Previous  Next


The KEYTRAP statement defines trap keys for use with INPUT @.





KEYTRAP (action, key), (action, key), ...




actionis a user defined value in the range 1 to 255 to be returned by the STATUS() function following an INPUT @ that is terminated by use of the key defined by key.

A negative action value removes the key binding specified by key.


keyidentifies the key to be bound to the given action. This is specified as a numeric value:
1 to 31Use the control key with this character value. Ctrl-A is 1, Ctrl-B is 2, etc.
32 to 159Use the Escape key followed a character value of key - 32 (e.g. Esc-A is 97).
160+Use a sequence of up to four characters constructed from the bytes sent by the key to be trapped starting from the low order byte plus 160. See below for an example.


The KEYTRAP statement defines one or more keys that will terminate an INPUT @ statement. When any of these keys in pressed the INPUT @ returns with the original value of the input variable. The STATUS() function will return the value defined by action for the key.


See the KEYEXIT statement for a method to return the input data as entered up to the moment when this key was used.



Example  of a multi-byte key sequence


The F2 key of a vt100 terminal using the vt100-at definition with AccuTerm sends a three character sequence of "Esc O Q". The hexadecimal values of these characters are 1B, 4F, 51. The key value is formed by concatenating bytes with these character values in reverse order and adding 160. The simplest way to do this is

  KEY = XTD('514F1B') + 160



See also: