KeyDown Event

Fired when a user presses a key.


Syntax

Private Sub object_KeyDown(KeyCode As Integer, ByVal Shift As Integer)

The syntax of the KeyDown event has these parts:

PartDescription
objectA DCombo control.
KeyCode  A key code, such as vbKeyF1 (the F1 key) or vbKeyHome (the HOME key). To specify key codes, use the constants in the Visual Basic (VB) object library in the Object Browser.
Shift  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.

Remarks

The keystroke can be changed or canceled by changing the value of KeyCode.

Data Type

KeyCode Integer
Shift Integer