registerFormKeys

registerFormKeys(array: IntegerArray);

The registerFormKeys method of the Form class enables you to establish the entire set of key codes in which key events of the receiver form are interested. The array parameter is populated with all key codes.

The keyUp, keyPress, and keyDown events are available for forms and for some controls (for example, TextBox and Table controls). By default, key events are received by the form and the control that has focus. The registerFormKeys method applies only to key event methods implemented for the form. The registerKeys method applies only to key event methods implemented for the control.

By default, if a form has key event methods defined, those key events are sent for any key event for any control on that form. In most situations, the form key events are interested only in specific keys (for example, the Tab key, arrow keys, and function keys).

After calling the registerFormKeys method with a key code list, the form key events are called on the form only if the key that is pressed is in the supplied list. This results in not having to call the form key events for every key action, which reduces the number of events that must be sent and processed.

You can use this process in both standard (fat) client and for thin client mode.

In the load method for a form shown in the following example, the Tab and the F2 function keys are registered as the only keys for which the form key events are called.

load();
vars
    aray : IntegerArray;
begin
    create aray transient;
    aray.add(9);          // Tab key
    aray.add(113);        // F2 key
    registerFormKeys(aray);
    delete aray;
end;

Calling the registerFormKeys method with a null value or with an empty key code list results in all keys that are pressed being sent to the form key events again. Each call to the registerFormKeys method entirely replaces any key code list that is currently in effect.

The key codes represent the actual physical keys. Registering the key code of 187 traps both the + and the = characters because they are the same key.

The Window class provides the class constants listed in the following table, which you can add to key code array parameter value to indicate that the key event should be sent only if the indicated special keys are also down when a specified key is pressed.

Window Class Constant Integer Value
RegisterKeys_Alt (#80000000)
RegisterKeys_Ctrl (#40000000)
RegisterKeys_Shift (#20000000)

You can use these class constants with a zero (0) key code array value, to indicate that the events for any key pressed are sent when that combination of special keys is also down (except for the special keys themselves). The method in the following example shows the use of these class constants.

load();
vars
    aray : IntegerArray;
begin
    create aray transient;
    aray.add(9);
    // Tab key, regardless of whether the Alt, Ctrl, or Shift keys are down
    aray.add(113 + RegisterKeys_Shift);
    // F2 key, only when Shift is also down
    aray.add(114 + RegisterKeys_Ctrl + RegisterKeys_Shift);
    // F3 key, only when Ctrl and Shift keys are both also down
    aray.add(RegisterKeys_Ctrl);
    // Any key pressed while the Ctrl key is down
    aray.add(RegisterKeys_Alt + RegisterKeys_Shift);
    // Any key pressed while Alt and Shift keys are both down
    registerFormKeys(aray);
    delete aray;
end;