xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

LastKey()

Returns the last Inkey() code retrieved.

Syntax

LastKey( [<nEventMask>] ) --> nLastInkeyCode

Arguments

<nEventMask>
A numeric value specifying the type of events LastKey() should retrieve. #define constants from INKEY.CH must be used for <nEventMask>. They are listed below:

Constants for <nEventMask>
ConstantValueEvents returned by LastKey()
INKEY_MOVE1Mouse pointer moved
INKEY_LDOWN2Left mouse button pressed
INKEY_LUP4Left mouse button released
INKEY_RDOWN8Right mouse button pressed
INKEY_RUP16Right mouse button released
INKEY_MMIDDLE32Middle mouse button pressed
INKEY_MWHEEL64Mouse wheel turned
INKEY_KEYBOARD128Key pressed
INKEY_ALL255All events are returned

IF <nEventMask> is omitted, the current SET EVENTMASK setting is used. If this is not issued, LastKey() returns only keyboard events.

Return

The function returns a numeric value identifying the last keyboard or mouse event retrieved by the Inkey() function.

Description

The LastKey() function returns the last keyboard or mouse event that was removed from the internal input buffers by the Inkey() function. LastKey() retains its value until the next pending key stroke or mouse event is removed from the internal input buffers by Inkey(). This way, the last Inkey code does not need to be preserved in a variable that must be passed to sub-routines for processing user input. Instead, user input can be queried with LastKey() until the next Inkey() call is made.

If only a subset of the Inkey codes is required, LastKey() can be passed a parameter <nEventMask> that filters Inkey codes retrieved from Inkey(). Only Inkey codes matching <nEventMask> are returned from LastKey().

Note:  the file INKEY.CH contains numerous symbolic #define constants that identify different key strokes or mouse input. It is recommended to use #define constants for prosessing Inkey codes, rather than using their numeric values.

Info

See also:Chr(), Inkey(), KEYBOARD, NextKey(), SetLastKey()
Category: Keyboard functions , Mouse functions
Header:Inkey.ch
Source:rtl\inkey.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// In this example, all possible user input is recognized by
// the Inkey() function. LastKey(), however, reports only
// key strokes and a left button click. Other mouse input
// is ignored by LastKey().

   #include "Inkey.ch"

   PROCEDURE Main
      LOCAL nEvent

      CLS
      ?? "Waiting for events (press ESC to quit)"
      SET EVENTMASK TO INKEY_ALL

      DO WHILE Lastkey() <> K_ESC
         nEvent := Inkey(0)

         nEvent := LastKey( INKEY_KEYBOARD + INKEY_LUP )
         IF nEvent == 0
            LOOP
         ENDIF

         @ 0, 0 CLEAR TO 1, MaxCol()

         IF nEvent >= K_MINMOUSE
            // display current mouse cursor position
            @ 0,1 SAY "Mouse Row:"
            ?? MRow()
            @ 1,1 SAY "Mouse Col:"
            ?? MCol()
         ELSE
            @ 0,1 SAY "Key Code:"
            ?? nEvent
         ENDIF
      ENDDO

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe