Progress
Language Reference


READKEY Statement

Interfaces
OS
SpeedScript
All
All
No

Reads one keystroke from an input source and sets the value of LASTKEY to the keycode of that keystroke. Use the READKEY statement when you want to look at each keystroke a user makes and take some action based on that keystroke.

SYNTAX

READKEY [ STREAM stream ] [ PAUSE n ] 

STREAM stream

Specifies the name of a stream. If you do not name a stream, Progress uses the unnamed stream. See the DEFINE STREAM Statement.

PAUSE n

The READKEY statement waits up to n seconds for a keystroke. If you do not press a key during that amount of time, READKEY ends, and sets the value in LASTKEY to -1.

PAUSE 0 causes READKEY to immediately return a value. If no character is available, READKEY sets the value of LASTKEY to -1. Use this form of READKEY to do polling through UNIX pipes or terminal ports.

EXAMPLE

In the following procedure, when the user presses a key, the READKEY statement reads the keystroke and stores the character code value of that key (the key code) as the value of LASTKEY. The CHR function converts the character code value into a character value. If the character value is a Y, Progress deletes the customer. KEYFUNCTION determines the function of the LASTKEY. If that function is END-ERROR, Progress exits the block, ending the procedure.

r-readky.p
FOR EACH customer:
  DISPLAY cust-num name address city st WITH 1 DOWN.
  MESSAGE "If you want to delete this customer, press Y".
  MESSAGE "Otherwise, press any other key.".
  READKEY.
  IF CHR(LASTKEY) = "Y" 
  THEN DELETE customer.
  ELSE IF KEYFUNCTION(LASTKEY) = "END-ERROR"
  THEN LEAVE.
END. 

NOTES

SEE ALSO

DEFINE STREAM Statement, LASTKEY Function


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095