How to get current modifier states with FireMonkey on OSX?

纵饮孤独 提交于 2019-12-01 06:30:59
Arjen van der Spek

Based on this answer you could try this:

function isCtrlDown : Boolean; 
begin
    Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
end;

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!