KeyPress

<< Click to Display Table of Contents >>

 

KeyPress

KeyPress(KeyAscii)

This event occurs when an object has the keyboard focus and users press a key, which corresponds to a character that can be displayed on screen, such as an ANSI key, with a code indicated by the KeyAscii parameter. This event occurs when any of the following keys is pressed:

Any printable keyboard character

The CTRL key combined with any standard alphabet character

The CTRL key combined with any special character

The BACKSPACE key, except for the Combo and Text objects

The ESC key

The ENTER key, except for the Text object

 

This event does not occur in the following conditions:

By pressing the TAB key

By pressing the DEL key, which is not a standard ANSI key

By pressing the arrow keys

By pressing a key that changes focus from one object to another

 

NOTES

This event does not occur in the Checkbox, Command Button, List, Option Button, and Toggle Button objects for any key.

This event does not occur in the Text object for the keys from 0 (zero) to 9 (nine) of the numeric keypad when the NUM LOCK key is deactivated.

This event does not occur in the Combo, Scrollbar, and Spin Button objects for the keys from 0 (zero) to 9 (nine) and the decimal point of the numeric keypad when the NUM LOCK key is deactivated.

 

While users press a key that produces an ANSI code, an object receives this event and the KeyDown event repeatedly. When users release that key, the KeyUp event occurs. To monitor keyboard's physical status or to handle keys not recognized by this event, such as function or browsing keys, use the KeyDown and KeyUp events.

 

NOTE

For a list with all key codes available for the KeyAscii parameter, please check the article Keys Enum on Microsoft Learn.

Was this page useful?