advr.hlp (Topic list)
KEY Statement (Event Trapping) Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 KEY(n%) {ON | OFF | STOP}
 
 Usage Notes
   ■ References to KEY statements when forms are showing generate an implicit
     KEY OFF event. Use form- and control-specific events with forms.
     See: Object Events Summary
 
   ■ To use the KEY statement with forms, you must first unload or hide any
     visible forms. See: HIDE Method  UNLOAD Statement
 
   ■ If your program contains event-handling statements and you are compiling
     from the BC command line, use the /W or /V option. If you do not use
     these options and your program contains event traps, Visual Basic
     generates the error message, "ON event without /V or /W on command
     line." See: BC Command-Line Options
 
   ■ KEY(n%) ON enables trapping of function keys, arrow keys, and user-
     defined keys. If key n% is pressed after a KEY(n%) ON statement, the
     routine specified in the ON KEY statement is executed.
 
   ■ KEY(n%) OFF disables trapping of key n%. No trapping takes place
     until another KEY(n%) ON statement is executed. Events occurring while
     trapping is off are ignored.
 
   ■ KEY(n%) STOP suspends trapping of key n%. No trapping takes place until
     a KEY(n%) ON statement is executed. Any ON KEY events that occur while
     trapping is suspended are remembered and processed when the next KEY(n%)
     ON is executed. However, remembered events are lost if KEY(n%) OFF is
     executed.
 
   ■ When a key event trap occurs (that is, the GOSUB is performed), an
     automatic KEY STOP is executed so that recursive traps cannot take
     place. The RETURN from a trapping routine automatically executes a
     KEY ON statement unless an explicit KEY OFF was performed inside the
     routine.
 
   ■ Visual Basic can also be used to trap shifted keys and other user-
     defined events. See: Declaring User-Defined Keys