Catch KeyPresses over whole form

From HashVB
Jump to: navigation, search
float
 This article is based on Visual Basic 6. Find other Visual Basic 6 articles.

A common question emerges from a need to catch keypresses form-wide.

Usually, when you have one or more controls on a form, a control, not the form, will have focus. This means that the form will not receive keypresses in its KeyPress, KeyDown and KeyUp events, which can cause difficulty with things like dialogs when trying to catch the escape key.

The solution to this is extremely simple: all you need to do is go into the properties box for the form, and set KeyPreview to True.

Voila :o)