使用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;
我的Cocoa应用程序支持将文件拖放到Dock图标上,但我想要根据是否按下修改键(命令,选项等)来执行不同的行为.
我尝试检查modifierFlagsfor currentEvent,但无论是否按下修饰符,它们都是相同的(我正在使用Option键进行测试).
码:
// Code is inside my AppDelegate
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)files {
BOOL optDown = (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
== NSAlternateKeyMask);
NSLog(@"flags: %u, down? %@", [[NSApp currentEvent] modifierFlags],
optDown ? @"YES" : @"NO");
}
Run Code Online (Sandbox Code Playgroud)
输出(使用Option键关闭文件,然后不丢弃):
flags: 1088, down? NO
flags: 1088, down? NO
Run Code Online (Sandbox Code Playgroud)
预期
flags: <not sure>, down? YES
flags: <different>, down? NO
Run Code Online (Sandbox Code Playgroud)