ON KEY Clause

 

ON KEY clauses can be included into the PROMPT statement to specify the behaviour of the keys pressed while the PROMPT statement is executed and the user input is performed. The keys can be assigned to form widgets and the actions will be 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. One PROMPT statement can contain any number of the ON KEY clauses, they can be placed in any order.

 

ON KEY clause can use one or several of the following keys separated by commas enclosed in parentheses to specify the key to which the other statements in ON KEY clause refer:

 

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, and X. The key names can be entered either in lower case or in upper case letters.

 

Any 4GL or SQL statements can be used in the ON KEY clause. These statements are executed when the key specified in the corresponding ON KEY clause is pressed.

 

When an ON KEY clause within the PROMPT statement is activated by pressing the corresponding key, the following actions are performed:

  1. The program control is passed to the corresponding ON KEY clause

  2. The statements of the ON KEY clause are executed

  3. The control is passed to the first statement that follows the END PROMPT keywords.

 

If the user presses the key specified in the ON KEY clause, this key is not typed in the PROMPT field. As the control does not return to the PROMPT statement after the ON KEY clause is executed, the value entered into the PROMPT field is assigned to the variable in the FOR clause. If the key is pressed before any value has been entered into the PROMPT field, the variable remains undetermined.

 

The value entered by the user can be changed by assigning a new value to the variable used in the FOR clause by means of the statements of an ON KEY clause.

 

PROMPT "Enter the date of order" ATTRIBUTE (REVERSE, GREEN) FOR ord_date

ATTRIBUTE (BLUE, CENTURY = "C")

ON KEY (F5)

LET ord_date = TODAY

END PROMPT

 

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

 

Key

Usage Features

ESC/ESCAPE

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

INTERRUPT

The DEFER INTERRUPT statement must be executed in order that this key could be used in the ON KEY clause. On pressing the Interrupt key the corresponding ON KEY clause is executed, int_flag is set to non-zero value

QUIT

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

CTRL-char

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

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

CTRL-char

(I, J, M)

These key combinations by default mean TAB, NEWLINE and RETURN. If they are used in the ON KEY clause, they cannot perform their default functions while the OK KEY clause is functional. Thus, if you use these keys in an ON KEY clause, the period of time during which this clause 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.