Specifying a function or subroutine to be called on keyboard interrupt

on interrupt

Specify function or subroutine to be called on keyboard interrupt


SYNTAX

on interrupt func_id | gosub label

Specifies a subroutine or function to be called if the user interrupts the program from the keyboard. In order for interrupts to be received, they must be enabled by setting the system variable sys.Interrupts to ON. By default it is OFF. The keyboard interrupt key is defined in the terminal parameter file, Section 2 (INFO), Sequence 8. It is normally CTRL-C or DEL.

When a keyboard interrupt occurs in a program with an on interrupt command, the specified subroutine or function is called after the processing of the current statement is completed. When the function or subroutine returns, processing continues with the next statement.

An input statement can be interrupted while it is awaiting input. In this case, when the subroutine or function returns, inputting continues from the point where it was interrupted.

The subroutine or function specification remains active until the program exits, unless overridden by a subsequent on interrupt command.

func_id

If the on interrupt command is not followed by a gosub then the next word must be the identifying name of a function in the program, defined by !function. The function is called with the interrupt number as an argument:

func_id(integer)

gosub label

If the gosub command is used, control passes to the statement at the line indicated by label. This should be the start of a block of code terminating with a return statement.


EXAMPLES

     on interrupt KeyInterrupt
     ...

!function KeyInterrupt(IntNum)
     ...

RELATED TOPICS

sys.Interrupts