keyDown

keyDown(keyCode: Integer io;           (Form)
        shift:   Integer);

keyDown(control: control-type input;   (Control)
        keyCode: Integer io;
        shift:   Integer);

The keyDown event occurs when the user presses a key while an object has focus. (To interpret ANSI characters, use the keyPress event.) This event uses the parameters listed in the following table.

Parameter Description
keyCode A key code; for example, J_key_F1 (F1 key) or J_key_Home (Home key).
shift The state of the Shift, Ctrl, and ALT keys when the key was pressed. This integer is a combination of values, as follows.
 
  • To test if the Shift value (1) is set, use if shift.bitAnd(1) <> 0 then

 
  • To test if the Ctrl value (2) is set, use if shift.bitAnd(2) <> 0 then

 
  • To test if the Alt value (4) is set, use if shift.bitAnd(4) <> 0 then

You can use the Window class constants listed in the following table to test the state of the Alt, Ctrl, and Shift keys of the shift parameter.

Window Class Constant Bit Value
KeyState_Alt #4
KeyState_Ctrl #2
KeyState_Shift #1

The keyDown event of the Form class first receives all keystrokes for all controls, followed by the object with the focus. Although the keyDown event can apply to most keys, it is most often used for:

Use the Window class enableEvent method to control at run time whether JADE logic associated with an event for a specific form or control is executed. You could use this method in thin client mode, for example, to speed up the data entry process for a TextBox control by disabling the keyDown event. (Event methods can be enabled or disabled in standard client mode and in thin client mode.)

Use the keyDown event for keyboard handlers if you need to respond to the pressing of a key.

When using a numeric text box (the inputType property is set to InputType_TextNumeric), the Form and TextBox class keyDown events are still fired when the entered key is invalid. This enables the form to process keys such as the Enter key in the Form::keyDown or keyPress events and the control to process these keys in its keyDown event, therefore allowing application users to use the numeric keypad when a form requires a large amount of numeric data entry.

Changing the keyCode parameter effects only the Form class. For control classes, Windows has already predetermined the actions taken.