Configuring a function key

on global

Configure a function key globally

on local

Configure a function key locally


SYNTAX

on global key_no func_id | gosub label | goto label [, …]
on local key_no func_id | gosub label | goto label [, …]

Configure a function key to call a function or subroutine, or to transfer control to a specified line. In addition to the function keys F1 - F32, a number of other special keys may be used (listed below).

The on local command configures the key for the duration of the current ring menu option only. The key is automatically cleared when control returns to the menu.

The on global command configures the key for the remainder of the program, unless it is reconfigured or cleared.

The function key is only active while the program is waiting for input during a dialog or at an input command. Pressing it at other times has no effect. It remains configured until the program terminates, until the current option ends (on local only) unless reconfigured for some other purpose by another on command, or disabled by means of the clearkey statement.

It is recommended that a function key be disabled while statements called by that key are being processed. This is because of the danger of recursion, should the key be left active in code containing an input statement. This can be avoided by temporarily disabling the key by means of the clearkey statement, and reconfiguring it when the statements it called have been executed.

If the function transfers input focus to a new control, any new content that had been typed into a textbox is not saved unless the save_text command is used inside the function. However, the contents of the field at the moment the function key was pressed are stored in the Sculptor system variable sys.InputBuf. If the textbox is multi-row, the row number is saved in sys.InputRow.

key_no

The key number is the sequence number of the key in Section 5 (“Sent by” sequences) of the terminal parameter file. The keys which are available for use have mnemonic definitions in $SCULPTOR/include/sculptor.h, and are as follows:

Key no

Definition

1 - 32

F1 - 32

38

HOME

39

ENDKEY

41

TAB

42

BACKTAB

49

INS_LINE

50

DEL_LINE

53

SCRL_UP

54

SCRL_DN

55

PGUP

56

PGDN

Either the key number (which may be an expression) or the mnemonic may be used.

func_id

If the function key identifier is not followed by a gosub or goto command then the next word must be the identifying name of a function in the program, defined by !function. When a key is used to call a function in this way, the function is called with the key_no as an argument:

func_id(key_no)

When the function returns, the dialog or input command continues at the point where it was interrupted.

The setfocus command may be used inside the function in order to move focus to a different control when the function returns. Alternatively, the function may return the control_id of the control that is to receive focus

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. When the subroutine returns, the dialog or input command continues at the point where it was interrupted.

goto label

If the goto command is used, control passes to the statement at the line indicated by label.

NOTES

  • These commands can be used to trap the F10 and SHIFT-F10 keys. When trapped, these keys no longer move focus to a menu. The keycodes for F10 and SHIFT-F10 are not sent to a keystroke event function, because this would prevent their default behaviour. This may change in a future version of Sculptor. In order to allow for future enhancements, a keycode event should always return OKAY or return with no explicit value.


EXAMPLES

Set several function keys to call functions:

on global F3 Help, F4 UserID, F5 Codes, F6 Control

Set function key to call a subroutine within current option only:

on local 16 gosub HELPWINDOW

RELATED TOPICS

clearkey

gosub

goto

setfocus

!function

sys.InputBuf

sys.InputRow

save_text