Sign in Join
FPDoc Onlineexperiment

GetKeyEventShiftState function

In unit keyboard

Return the current state of the shift keys.

Declaration

pascal
function GetKeyEventShiftState(KeyEvent: TKeyEvent): Byte

Description

GetKeyEventShiftState returns the shift-state values of the given KeyEvent. This can be used to detect which of the modifier keys Shift, Alt or Ctrl were pressed. If none were pressed, zero is returned.

Note that this function does not always return expected results; In a UNIX X-Term, the modifier keys do not always work.

Errors

None.

See also

Example: ex3

pascal
Program Example3;

{ Program to demonstrate the GetKeyEventShiftState function. }

Uses keyboard;

Var
  K : TKeyEvent;
  S : Byte;

begin
  InitKeyBoard;
  Write('Press keys combined with CTRL/SHIFT/ALT');
  Writeln(', or press "q" to end.');
  Repeat
    K:=GetKeyEvent;
    K:=TranslateKeyEvent(K);
    S:=GetKeyEventShiftState(K);
    If (S=0) then
      Writeln('No special keys pressed')
    else
      begin
      Writeln('Detected special keys : ',ShiftStateToString(K,False));
      Writeln('Got key : ',KeyEventToString(K));
      end;
  Until (GetKeyEventChar(K)='q');
  DoneKeyboard;
end.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.