
7-6
Section
Details of BASIC Commands
181
on key
Syntax:
ON KEY
[<key expression>] (
GOTO
|
GOSUB
) ( <line number> | <label>)
Description:
Statement. An interrupt subroutine is executed when the specified key (0 to 9) is input from the
keyboard. (Valid only when a terminal is connected.)
Remarks:
<key expression> is an integer expression returning a value in the range : [0…9]. there should
only be one
ON KEY GOTO
/
GOSUB
statement for each <key expression>. If the <key expression> is
omitted the interrupt is activated for all key inputs.
<line number> specifies the line at the start of the interrupt subroutine (ISR).
<label> is a BASIC program label. It references a line number somewhere in the BASIC program.
If the
GOSUB
statement is used for branching, the ISR should be terminated by a
RETURN
statement. When the
RETURN
statement is reached execution will resume at the statement after the
statement that was originally interrupted.
A value outside this range results in a “FORMAT ERROR” (code B067).
The interrupt will be on standby when the
PC READ
/
PC WRITE
(including @) commands are
executing for an
ON KEY GOSUB
statement.
The port connecting the keyboard must first be opened using an
OPEN
statement.
Pressing the “1” key on the keyboard will execute the key(1) branch, pressing the “2” key will
execute the key(2) branch, and so on. During the execution of
ON KEY GOSUB
routines all BASIC
interrupts are
STOP
ped until the
RETURN
statement has been executed.
On executing the corresponding
ON KEY
ISR, all subsequent BASIC interrupts are stopped, i.e.
held pending during execution of the ISR. After the ISR has returned, pending interrupts are
executed and the BASIC interrupts are returned to their previous states. Only one interrupt of the
same type as the currently active interrupt can be held pending, subsequent interrupts of that type
are lost.
For more information on writing interrupts in BASIC refer to the
ON COM
and
ON PC
examples in
5.5 Interrupt Functions.
Examples:
> 10 ON KEY 1 GOSUB 60
> 20 ON KEY 2 GOSUB 80
> 30 ON KEY 3 GOSUB 100
> 40 KEY ON
> 50 GOTO 50
> 60 PRINT "1 PRESSED"
> 70 RETURN
> 80 PRINT "2 PRESSED"
> 90 RETURN
> 100 PRINT "3 PRESSED"
> 110 RETURN
> RUN
See also:
KEY
(
ON
|
OFF
|
STOP
)
Summary of Contents for C200H-ASC11
Page 1: ...C200H ASC11 ASC21 ASC31 ASCII Units Operation Manual Revised June 2000...
Page 2: ...iv...
Page 4: ...vi...