
Chapter 9. Event Polling and Error/Event Trapping
151
9.4 Event (of Keystroke) Trapping
[ 1 ] Overview
If any of the function keys previously specified for keystroke trapping is pressed, event trapping
makes the program cause an interrupt so as to transfer control from the current program to the
specified event-handling routine.
This trapping facility checks whether any of the function keys is pressed or not between every
execution of the statements.
[ 2 ] Programming for trapping keystrokes
To trap keystrokes, use both the
ON
KEY
...
GOSUB
and
KEY
ON
statements. The
ON
KEY
...
GOSUB
statement designates the key number of the function key to be trapped and the
event-handling routine (to which control is to be transferred if a specified function key is
pressed) in its label. The
KEY
ON
statement activates the designated function key.
This trapping cannot take effect until both the
ON
KEY
...
GOSUB
and
KEY
ON
statements have
been executed.
The keystroke of an unspecified function key or any of the numerical keys cannot be trapped.
The following program sample will trap keystroke of magic keys M1 and M2 (these keys are
numbered 30 and 31, respectively).
ON KEY (30) GOSUB sub1
ON KEY (31) GOSUB sub2
KEY (30) ON
KEY (31) ON
.
.
.
(Main routine)
.
.
.
END
sub1
(Event-handling routine 1)
RETURN
sub2
(Event-handling routine 2)
RETURN
The
RETURN
statement in the event-handling routine will return control to the statement imme-
diately following that statement where the keyboard interrupt occurred.
Even if a function key is assigned a null string by the
KEY
statement, pressing the function key
will cause a keyboard interrupt when the
KEY
ON
statement activates that function key.
Summary of Contents for BHT-BASIC 100 SERIES
Page 1: ......
Page 161: ...153 Chapter 10 Sleep Function CONTENTS 10 1 Sleep Function 154...
Page 163: ...155 Chapter 11 Resume Function CONTENTS 11 1 Resume Function 156...
Page 173: ...165 Chapter 13 Backlight Function CONTENTS 13 1 Backlight Function 166...
Page 249: ...241 Example CLOSE IF kyIn Y THEN KILL Master Dat END IF Reference Statements CLFILE...