Catch KeyPresses over whole form

From HashVB
Revision as of 14:01, 9 November 2005 by Dee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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)