KeyUp

This event occurs when a user releases a key while an object has the focus.

Syntax

Private Sub object_KeyUp(keycode, shift)

Parameters

object
Object expression that evaluates to a control or Form object.
keycode
Key code, such as vbKeyHome (the HOME key).
shift
Integer that corresponds to the state of the SHIFT, CTRL, and ALT keys at the time of the event.

Remarks

The object with the focus receives all keystrokes. A form can have the focus only if it has no visible and enabled controls.

If the KeyPreview property is set to True, a form receives these events before controls on the form receive the events. Use the KeyPreview property to create global keyboard-handling routines.

Use the KeyUp event procedure if you need to respond to both the pressing and releasing of a key.

Do not invoke the KeyUp event for the following keys:

The following table shows the values for the shift constants.

Constant
Value
Description
vbShiftMask 1 SHIFT key bit mask.
vbCtrlMask 2 CTRL key bit mask.
vbAltMask 4 ALT key bit mask.

The constants act as bit masks that you can use to test for any combination of keys.

To interpret ANSI characters, use the KeyPress event.