Skip to content

GetKeyEvent

Get the next raw key event, wait if needed.

Declaration

Source position: keybrdh.inc line 148

  function GetKeyEvent : TKeyEvent;

Description

GetKeyEvent returns the last keyevent if it is available, or waits for one if none is available. A non-blocking version is available in PollKeyEvent .

The returned key is encoded as a TKeyEvent type variable, and is normally the physical key scan code, (the scan code is driver dependent) which can be translated with one of the translation functions TranslateKeyEvent or TranslateKeyEventUniCode . See the types section for a description of how the key is described.

Errors

If no key became available (e.g. when the driver does not support it), 0 is returned.

See also

Name Description
PollKeyEvent Get next key event, but does not wait.
PutKeyEvent Put a key event in the event queue.
TranslateKeyEvent Translate raw event to ascii key event
TranslateKeyEventUniCode Translate raw event to UNICode key event

Example

program example1;
{ This program demonstrates the GetKeyEvent function }
uses keyboard;
Var
  K : TKeyEvent;
begin
  InitKeyBoard;
  Writeln('Press keys, press "q" to end.');
  Repeat
    K:=GetKeyEvent;
    K:=TranslateKeyEvent(K);
    Write('Got key event with ');
    Case GetKeyEventFlags(K) of
      kbASCII    : Writeln('ASCII key');
      kbUniCode  : Writeln('Unicode key');
      kbFnKey    : Writeln('Function key');
      kbPhys     : Writeln('Physical key');
      kbReleased : Writeln('Released key event');
    end;
    Writeln('Got key : ',KeyEventToString(K));
  Until (GetKeyEventChar(K)='q');
  DoneKeyBoard;
end.