Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
KeyDown, KeyUp Events Details
◄Summary► ◄Details► ◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
SUB Form_KeyDown (KeyCode AS INTEGER, Shift AS INTEGER)
SUB ctlname_KeyDown ([Index AS INTEGER,]KeyCode AS INTEGER,
Shift AS INTEGER)
SUB Form_KeyUp (KeyCode AS INTEGER, Shift AS INTEGER)
SUB ctlname_KeyUp ([Index AS INTEGER,]KeyCode AS INTEGER, Shift AS INTEGER)
Usage Notes
■ Use KeyDown and KeyUp event procedures to handle keyboard routines when
forms are showing. The ON KEY statement will not work when forms are
showing.
■ For both KeyDown and KeyUp events, the object with the focus receives
all keystrokes, but a form can have the focus only if it has no visible
or enabled controls. See: ◄Focus Definition►
■ KeyCode values for ASCII-printable keys (A-Z, a-z, 0-9, ~, [, ], {, },
+, =) are the same as their ASCII equivalents. In Visual Basic for DOS,
the returned KeyCode value differentiates between uppercase and
lowercase, and returns the same value as the KeyAscii parameter used in
the KeyPress event procedure. See: ◄KeyPress Event►
■ Use shortcut and access keys for keyboard shortcuts instead of code
that responds to KeyDown and KeyUp events; these keys require no
additional code. You can program these keys when creating menus in the
Form Designer.
■ Although KeyDown and KeyUp events can detect all keys, they are most
often used for:
• Extended character keys such as function keys
• Navigation keys
• Combinations of the Shift, Ctrl, and Alt keys (keyboard modifiers)
• Distinguishing between the numeric keypad and regular number keys
■ Use KeyDown and KeyUp event procedures to write keyboard handlers if you
want your application to respond to both the press and release of a key.
■ KeyDown and KeyUp are not invoked for the following keys and conditions:
Key Condition
═════════ ════════════════════════════════════════════════════════════
Enter If the form has a command button with the Default property
set to True (-1)
Esc If the form has a command button with the Cancel property
set to True (-1)
Tab If two or more controls are on the form