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.
ON KEY Statement Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 ON KEY(n%) GOSUB {linenumber | linelabel}
 
 Usage Notes
   ■ Use the KeyDown, KeyPress, and KeyUp events to handle keyboard input
     with forms. ON KEY will not work when forms are showing.
     See: KeyDown Event  KeyPress Event  KeyUp Event
 
   ■ To use the ON 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
 
   ■ The RETURN linenumber or RETURN linelabel forms of RETURN can be used
     to return to a specific line from a trapping routine. However, any
     GOSUB, WHILE, or FOR statements active at the time of the trap remain
     active. Visual Basic may generate error messages such as "NEXT without
     FOR."
 
   ■ Keys are processed in the following order:
     • The line printer's echo-toggle key is processed.
       Defining this key as a user-defined key trap does not prevent
       characters from being echoed to the line printer when pressed.
     • Function keys and the arrow keys are examined.
       Defining a function key or arrow key as a user-defined key trap has
       no effect because these keys are predefined.
     • The user-defined keys are examined.
 
   ■ The ON KEY statement can trap any key, including Break or System Reset
     (Ctrl+Alt+Del). This makes it possible to prevent accidentally breaking
     out of a program or rebooting the machine.
 
   ■ The ON KEY statement specifies only the start of an event-trapping
     routine. The KEY statement determines whether the routine is called
     and how events are handled when trapping is off. See: KEY Statement
 
   ■ If an event occurs in a procedure, a RETURN linenumber or RETURN
     linelabel statement cannot get back into the procedure, because the
     line number or label must be in the module-level code.
 
   ■ After a key is trapped, the information specifying which key was
     trapped is no longer available. This means that you cannot subsequently
     use an INPUT statement or INKEY$ function to find out which key caused
     the trap. Because you do not know which keypress caused the trap,
     you must create a different event-handling routine for each key you
     want to trap.