Share via


Visual Basic Concepts

Responding to Keyboard Events

Keyboard events, along with mouse events, are the primary elements of a user's interaction with your program. Clicks and key presses trigger events and provide the means of data input and the basic forms of window and menu navigation.

Although the operating system provides the seamless back-end for all these actions, it's sometimes useful or necessary to modify or enhance them. The KeyPress, KeyUp, and KeyDown events allow you to make these modifications and enhancements.

Programming your application to respond to key events is referred to as writing a keyboard handler. A keyboard handler can work on two levels: at the control level and at the form level. The control level (low-level ) handler allows you to program a specific control. For instance, you might want to convert all the typed text in a Textbox control to uppercase. A form-level handler allows the form to react to the key events first. The focus can then be shifted to a control or controls on the form, and the events can either be repeated or initiated.

With these key events you can write code to handle most of the keys on a standard keyboard. For information on dealing with international character sets and keyboards, see "International Issues."