xHarbour Reference Documentation > Function Reference |
Returns the last Inkey() code retrieved.
LastKey( [<nEventMask>] ) --> nLastInkeyCode
Constants for <nEventMask>
Constant | Value | Events returned by LastKey() |
---|---|---|
INKEY_MOVE | 1 | Mouse pointer moved |
INKEY_LDOWN | 2 | Left mouse button pressed |
INKEY_LUP | 4 | Left mouse button released |
INKEY_RDOWN | 8 | Right mouse button pressed |
INKEY_RUP | 16 | Right mouse button released |
INKEY_MMIDDLE | 32 | Middle mouse button pressed |
INKEY_MWHEEL | 64 | Mouse wheel turned |
INKEY_KEYBOARD | 128 | Key pressed |
INKEY_ALL | 255 | All events are returned |
IF <nEventMask> is omitted, the current SET EVENTMASK setting is used. If this is not issued, LastKey() returns only keyboard events.
The function returns a numeric value identifying the last keyboard or mouse event retrieved by the Inkey() function.
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.
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 |
// 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
http://www.xHarbour.com