How to get current modifier states with FireMonkey on OSX?

后端 未结 2 1907
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 11:05

With Delphi for Windows, I usually use this code:

function isCtrlDown : Boolean;
var
  ksCurrent : TKeyboardState;
begin
  GetKeyboardState(         


        
相关标签:
2条回答
  • 2021-01-13 11:35

    This returns the current shift state:

    uses
      Macapi.CoreGraphics;
    
    function KeyboardModifiers: TShiftState;
    const
      kVK_Shift                     = $38;
      kVK_RightShift                = $3C;
      kVK_Control                   = $3B;
      kVK_Command                   = $37;
      kVK_Option                    = $3A;
    begin
      result := [];
      if (CGEventSourceKeyState(0, kVK_Shift) <> 0) or (CGEventSourceKeyState(0, kVK_RightShift) <> 0) then Include(result, ssShift);
      if CGEventSourceKeyState(0, kVK_Command) <> 0 then Include(result, ssCommand);
      if CGEventSourceKeyState(0, kVK_Option) <> 0 then Include(result, ssAlt);
      if CGEventSourceKeyState(0, kVK_Control) <> 0 then Include(result, ssCtrl);
    end;
    
    0 讨论(0)
  • 2021-01-13 11:37

    Based on this answer you could try this:

    function isCtrlDown : Boolean; 
    begin
        Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
    end;
    
    0 讨论(0)
提交回复
热议问题