Ask for the Shift-Key-Status on Linux

Issue #180 resolved
Harry Stahl created an issue

I use this to ask for the shift-key status on windows and Mac. How can I do this on Linux? Is it allready possible or can you enhance it here?

function IsShiftKeyPressed: Boolean;
begin
{$IFDEF MSWINDOWS}
  Result := GetKeyState(VK_SHIFT) < 0;
{$ENDIF}

{$IFDEF MacOS}
  Result := NSShiftKeyMask and TNSEvent.OCClass.modifierFlags = NSShiftKeyMask;
{$ENDIF}

{$IFDEF Linux}
  //Result := GetKeyState(VK_SHIFT) < 0;
{$ENDIF}
end;

Comments (5)

  1. Eugene Kryukov repo owner

    Actually there is no such easy way on GTK (only using key snooper), we will try to implement it.

  2. Eugene Kryukov repo owner

    We tried few approach but no one works perfect. There is no way to handle Shift key down on Linux (GTK). We will continue investigation.

  3. Zoltan Karpati

    Harry, I hope this helps to you:

    http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.Classes.TShiftState

    I am using the following code to move the 3d object on the Viewport3D (If Shift key pressed and mouse is moved). It works fine on Windows, macOS, Linux.

    procedure TMainForm.Viewport3DMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Single);
    begin
        if (ssShift in Shift) and Mouse then
           begin
              Dummy.Position.X := Dummy.Position.X + (X - Down.X)* 0.025 ;    
              Dummy.Position.Y := Dummy.Position.Y + (Y - Down.Y)* 0.025 ; 
    
              Down.X := X;
              Down.Y := Y;
           end;
    end;
    
    procedure TMainForm.Viewport3DMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Single);
    begin
      Mouse:=true;
      Down:=PointF(X,Y);
    end;
    
    procedure TMainForm.Viewport3DMouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Single);
    begin
      Mouse:=false;
    end;
    
  4. Harry Stahl reporter
    1. Thank you Eugene, for investigation.

    2. Thank you Zoltan, for this idea. I use this Shift-Status as modifier, for example, when I press a delete button, and when shift is pressed, there will be no verification dialog "do you want really delete this...". But pressing the Button give us the shiftstate in mousedown (and also in Keydown). So I can save this shiftstatus temporary and use the status, when is it needed.

  5. Log in to comment