FUNCTIONS CT

SetLastKey()

Change the value returned by LastKey()

Syntax

Signature
SetLastKey( nKey ) --> cNull

Arguments

nKey

The key code that LastKey() returns from now on.

Return value

Always "".

Description

SetLastKey() sets LastKey() without a key press. Use it to save LastKey() before code that reads keys, for example an error handler, and to restore it afterwards.

Notes

The keyboard buffer does not change: Inkey() and NextKey() are not affected.

Example

SetLastKey.prg
#include "inkey.ch"

PROCEDURE Main()

   LOCAL nSaved := LastKey()

   Check( 'SetLastKey( K_ESC ) gives ""     ', SetLastKey( K_ESC ), "" )
   Check( 'LastKey() after SetLastKey()     ', LastKey(), K_ESC )

   SetLastKey( nSaved )
   Check( 'LastKey() restored               ', LastKey(), nSaved )

RETURN

STATIC PROCEDURE Check( cTitle, xResult, xExpected )

   QOut( cTitle + IIF( xResult == xExpected, "OK", "ERROR" ) )

RETURN

Output

SetLastKey( K_ESC ) gives ""     OK
LastKey() after SetLastKey()     OK
LastKey() restored               OK

See also