Occur when the user presses and releases an ANSI key.
Sub object_KeyPress([index%,] Ascii&)
object:Ocx Object
index:iexp
Ascii&Short exp
The KeyPress event syntax has these parts:
index%An integer that uniquely identifies a control or form if it's in an array.
Ascii&An integer that returns a standard numeric ANSI keycode. Ascii& is passed by reference; changing it sends a different character to the object. For a full list of ASCII and ANSI (Windows 1252) values, see Key Codes and ASCII Values.
Changing Ascii& to 0 cancels the keystroke so the object receives no character.
Changing the value of the Ascii& argument changes the character displayed.
Form frm1 = "Key Press", 20, 20, 300, 300 : .FontName = "courier new"
Do
Sleep
Until Me Is Nothing
Sub frm1_KeyPress(Ascii&)
// Converts any key pressed to upper case
Local ch$ = Upper(Chr(Ascii&))
Ascii& = Asc(ch$)
Print ch$;
EndSub
Use KeyDown and KeyUp event procedures to handle any keystroke not recognized by KeyPress, such as function keys, editing keys, navigation keys, and any combinations of these with keyboard modifiers. Unlike the KeyDown and KeyUp events, KeyPress doesn't indicate the physical state of the keyboard; instead, it passes a character.
Use the Screen_KeyPreview event to create global keyboard-handling routines. This event sub receives these events before controls or the form receives the events.
Form, KeyUp, KeyDown, Screen_KeyPreview
{Created by Sjouke Hamstra; Last updated: 11/10/2014 by James Gaite}