ON KEY Clause

 

ON KEY control blocks are used to define the actions to be executed when the user presses a specific key combination. This key combination can be assigned to a form widget and the actions are triggered when such widget is pressed. However, if a key combination is not assigned to any widget, it can be activated with the help of the keyboard.

 

The following keywords can be specified in the Key List:

 

ESC/ESCAPE

ACCEPT

NEXT/ NEXTPAGE

PREVIOUS/PREVPAGE

INSERT

DELETE

RETURN

TAB

INTERRUPT

HELP

LEFT

RIGHT

UP

DOWN

F1 – F256

CONTROL-char

 

Any character can be used as char in the combination CONTROL-char except the following characters: A, D, H, I, J, K, L, M, R, or X.

 

Some keys require special attention if used in the ON KEY block:

 

Key

Usage Features

ESC/ESCAPE

If you want to use this key in ON KEY block, you must specify another key as the Accept key in the OPTIONS block, because ESCAPE is the Accept key by default

F3

It is the default Next key, if you want to use it in the ON KEY block, you must specify another key as the Next key in the OPTIONS block

F4

It is the default Previous key, if you want to use it in the ON KEY block, you must specify another key as the Previous key in the OPTIONS block

INTERRUPT

DEFER INTERRUPT statement must be executed in order that this key could be used in the ON KEY block. On pressing the INTERRUPT key the corresponding ON KEY block is executed, int_flag is set to non-zero but the CONSTRUCT statement is not terminated

QUIT

DEFER QUIT statement must be executed in order that this key could be used in the ON KEY block. On pressing the QUIT key the corresponding ON KEY block is executed and int_flag is set to non-zero

CTRL-char

(A, D, H, L, R, X)

4GL reserves these keys for field editing and they should not be used in the ON KEY block

CTRL-char

(I, J, M)

These key combinations by default mean TAB, NEWLINE and RETURN. If they are used in the ON KEY block, they cannot perform their default functions while the OK KEY block is functional. Thus, if you use these keys in the ON KEY block, the period of time during which this block is functional should be restricted.

 

Some restrictions in key usage might be applied depending on your operational system. Many systems use such key combinations as CONTROL-C, CONTROL-Q, and CONTROL-S for the Interrupt, XON, and XOFF signals.

 

When an ON KEY block is present within the input control block, 4GL takes the following actions:

The input in to the current field is temporally suspended.

The characters entered by the user are preserved in the input buffer.

The statements included into the corresponding ON KEY block are executed.

The input buffer is restored for the current field.

The input in the field is restored with the cursor being at the end of the list of characters extracted from the buffer.

 

This default set of actions can be changed. The input may be resumed not for the same field but for any field of your choice, if the corresponding ON KEY block contains the NEXT FIELD clause.

 

ON KEY (CONTROL-G)

IF lname IS NOT NULL THEN

NEXT FIELD address

      END IF

 

It is also possible to change the value for the corresponding variable preserved in the input buffer and to display the changed value to the field by placing the necessary statements in the ON KEY block.

 

ON KEY (F12)

LET curr_f = "N/A"

 

You can specify up to four keys in one ON KEY clause, pressing any of these keys will result in executing the ON KEY clause. The key names must be enclosed in parentheses and separated by comas.