advr.hlp (Topic list)
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.
KeyPress Event Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 SUB Form_KeyPress (KeyAscii AS INTEGER)
 SUB ctlname_KeyPress ([Index AS INTEGER] KeyAscii AS INTEGER)
 
 Usage Notes
   ■ A KeyPress event can involve:
     • Any printable keyboard character
     • The Ctrl key + a character from the standard alphabet or one of a few
       special characters
     • The Enter key
     • The Backspace key
 
   ■ A KeyPress event procedure is useful for intercepting keystrokes entered
     in a text box or combo box. It allows you to immediately test keystrokes
     for validity or to format characters as they are typed.
 
   ■ KeyAscii is passed by reference; changing it sends a different character
     to the object. This can be useful in a password scheme that uses a text
     box where you do not want the entered password to be displayed.
 
   ■ Changing KeyAscii to zero (0) cancels the keystroke so that the object
     does not receive the character.
 
   ■ You can convert the KeyAscii argument into a character by using the
     expression CHR$(KeyAscii). You can then perform string operations and
     translate the character back to an ASCII format that the control can
     understand by using this expression:
 
         KeyAscii =  ASC("x")
 
   ■ Use KeyDown and KeyUp event procedures to handle non-ASCII keystrokes
     such as:
     • Function keys
     • Editing keys
     • Navigation keys
     • Any combination of the above with the Shift, Ctrl, and Alt keys
       (keyboard modifiers)
 
   ■ KeyPress interprets the uppercase and lowercase of each character as
     separate key codes and therefore as separate characters.