Whi*_*ler 5 delphi macos keyevent delphi-xe2 firemonkey
使用Delphi for Windows,我通常使用以下代码:
function isCtrlDown : Boolean;
var
ksCurrent : TKeyboardState;
begin
GetKeyboardState(ksCurrent);
Result := ((ksCurrent[VK_CONTROL] and 128) <> 0);
end;
Run Code Online (Sandbox Code Playgroud)
如何在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;
}
Run Code Online (Sandbox Code Playgroud)
我还在调查......现在,我发现这个单位有关键事件 ......
unit Macapi.AppKit;
这将返回当前的移位状态:
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;
Run Code Online (Sandbox Code Playgroud)
根据这个答案,你可以尝试这个:
function isCtrlDown : Boolean;
begin
Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
end;
Run Code Online (Sandbox Code Playgroud)