Try OpenEdge Now
skip to main content
ABL Reference
ABL Syntax Reference : LASTKEY function
 

LASTKEY function

Returns, as an INTEGER value, the integer key code of the most recent event read from the user (that is, from the keyboard or mouse) during an interaction with a procedure.
Note: Does not apply to SpeedScript programming.

Syntax

LASTKEY

Example

In this procedure, the user can move through the Customer file and update certain fields in each of the Customer records. The GO-ON option tells the procedure to continue on to the following statements if the user presses F9, F10, or F12. To determine what action to take, the LASTKEY function compares the key code of the last key pressed with the key codes F9, F10, and F12.
r-lastky.p
DISPLAY "You may update each customer. After making your changes," SKIP
  "Press one of:" SKIP(1)
KBLABEL("GO") "Make the changes permanent" SKIP
KBLABEL("END-ERROR") "Undo changes and exit" SKIP
"F9" SPACE(7) "Undo changes and try again" SKIP
"F10" SPACE(6) "Find next customer" SKIP
"F12" SPACE(6) "Find previous customer"
WITH CENTERED FRAME instr.

FIND FIRST Customer.

REPEAT:
  UPDATE Customer.CustNum Customer.Name Customer.Address Customer.City
    Customer.State GO-ON(F9 F10 F12) WITH 1 DOWN.
       IF LASTKEY = KEYCODE("F9")  THEN UNDO, RETRY.
  ELSE IF LASTKEY = KEYCODE("F10") THEN FIND NEXT Customer.
  ELSE IF LASTKEY = KEYCODE("F12") THEN FIND PREV Customer.
END.

Notes

*The LASTKEY function is double-byte enabled. The LASTKEY function returns values only after the input method places the data in the keyboard buffer. It returns the key code of the most recent key sequence returned from the keyboard buffer. A key sequence is the set of keystrokes necessary to generate one character or function key event in ABL.
*If you used a READKEY statement that timed out (you specified a number of seconds by using the PAUSE option with the READKEY statement), or if a PAUSE statement times out, the value of LASTKEY is -1.
*If you use the PAUSE option with the READKEY statement, the value of LASTKEY is the key you press to end the PAUSE.
*When the ABL session starts, the value of LASTKEY is -1. This value remains the same until the first input, READKEY, or procedure pause occurs. The LASTKEY function is reset to -1 each time you return to the Procedure Editor.
*If you read data from a file, LASTKEY is set to the last character read from the file. For an INSERT, PROMPT-FOR, SET or UPDATE statement, this is always KEYCODE("RETURN"). For a READKEY statement, this is the character read from the file. If you reach past the end of the file, LASTKEY is -2.
*For more information on keys, see OpenEdge Development: Programming Interfaces.

See also

READKEY statement