对于Windows的 Delphi ,我通常使用以下代码:
function isCtrlDown : Boolean;
var
ksCurrent : TKeyboardState;
begin
GetKeyboardState(ksCurrent);
Result := ((ksCurrent[VK_CONTROL] and 128) <> 0);
end;
如何在Mac OSX上使用FireMonkey实现此目的?
我找到this,但我不知道如何使用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;
答案 0 :(得分:4)
这将返回当前的班次状态:
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;
答案 1 :(得分:2)
根据此answer,你可以试试这个:
function isCtrlDown : Boolean;
begin
Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
end;