5

使用Delphi for Windows,我通常使用以下代码:

function isCtrlDown : Boolean;
var
  ksCurrent : TKeyboardState;
begin
  GetKeyboardState(ksCurrent);
  Result := ((ksCurrent[VK_CONTROL] and 128) <> 0);
end;

如何在 Mac OSX 上使用 FireMonkey 实现这一点?

我找到了这个,但我不知道如何使用 FireMonkey/Delphi(它使用...)来管理它:

void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
{
    UInt32 currentModifiers = GetCurrentKeyModifiers();
    shiftKey = currentModifiers & ::shiftKey;
    ctrlKey = currentModifiers & ::controlKey;
    altKey = currentModifiers & ::optionKey;
    metaKey = currentModifiers & ::cmdKey;
}

我还在调查……目前,我已经找到了这个单元,里面有关键事件的东西…… unit Macapi.AppKit;

4

2 回答 2

5

这将返回当前的班次状态:

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;
于 2012-10-14T08:12:38.127 回答
2

根据这个答案,你可以试试这个:

function isCtrlDown : Boolean; 
begin
    Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
end;
于 2012-10-14T07:28:57.803 回答