Occurs when the user presses a key while an object has the focus.
![]() | Type | Description | ||
| KeyCode as Integer | An integer that represent the key code. | |||
| Shift as Integer | An integer that corresponds to the state of the SHIFT, CTRL, and ALT keys at the time of the event. The shift argument is a bit field with the least-significant bits corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT key (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Some, all, or none of the bits can be set, indicating that some, all, or none of the keys are pressed. For example, if both CTRL and ALT are pressed, the value of shift is 6. |
Use KeyDown and KeyUp event procedures if you need
to respond to both the pressing and releasing of a key. Use the ExpandOnKeys
property to specify whether the user expands or collapses the focused items
using arrow keys. You test for a condition by first
assigning each result to a temporary integer variable and then comparing shift to a bit
mask. Use the And operator with the shift argument to test whether the condition is
greater than 0, indicating that the modifier was pressed, as in this example:
ShiftDown = (Shift And 1) > 0
CtrlDown = (Shift And 2) > 0
AltDown = (Shift And 4) > 0
In a procedure, you can test for any combination of conditions, as in this example:
If AltDown And CtrlDown Then