ON ESCAPE Command
Specifies a command that executes when you press the ESC key during program or command execution.
ON ESCAPE [Command]
- Specifies the Visual FoxPro command to execute. After the command executes, program execution resumes on the line immediately following the program line that was executing when you pressed ESC. However, if a procedure specified with ON ESCAPE includes RETRY, the program line that was executing when you pressed ESC executes again.
Typically, ON ESCAPE uses DO to execute a procedure.
If both ON ESCAPE and ON KEY are in effect and you press ESC, Visual FoxPro executes the command specified with ON ESCAPE.
Use ON ESCAPE without a command to cause no command to execute when ESC is pressed (the default).
Note Visual FoxPro doesn't execute an ON ESCAPE routine if SET ESCAPE is OFF.
The following example sets up an infinite loop but defines an ON ESCAPE routine to exit it.
SET ESCAPE ON ON ESCAPE DO stopit WAIT WINDOW 'Press ESC to stop loop' NOWAIT glMoreLoop = .T. DO WHILE glMoreLoop ENDDO RETURN PROCEDURE stopit glMoreLoop = .F. RETURN