Links are not active on this page.
 ON KEY Command

Included for backward compatibility. Use ON KEY LABEL instead.

This command is undocumented in the original VFP9 help file,
but the following documentation was found in the FoxPro for Windows 2.6 help, and may still be valid:

Specifies a command that executes when you press any key during program execution.

ON KEY
	[command]

Expand imageRemarks


When you press any key during program execution, FoxPro executes the command you specify with ON KEY. Typically, ON KEY uses DO to execute a procedure.

After the command that you specified with ON KEY executes, program execution resumes on the line immediately following the program line that was executing when a key was pressed. However, if a procedure specified with ON KEY includes RETRY, the program line that was executing when a key was pressed executes again.

Use ON KEY without a command to cause no command to execute when a key is pressed (the default).

If both ON KEY and ON ESCAPE are in effect and Esc is pressed, the command specified with ON ESCAPE is executed.

Expand imageExample

In this example, records from the CUSTOMER table are displayed. If a key is pressed while the records are being displayed, the procedure named PAUSE is called. PAUSE uses WAIT to suspend display.

CopyCode imageCopy Code
SET TALK OFF
USE customer
CLEAR
ON KEY DO pause
DO WHILE NOT EOF()
	? 'Company: ' + company
	? 'Address: ' + address
	?
	SKIP
ENDDO
PROCEDURE pause
STORE INKEY() TO HOLD
WAIT
RETURN

Expand imageSee Also