How to get current modifier states with FireMonkey on OSX?

delphi, delphi-xe2, firemonkey, keyevent, macos

Solution

Based on this answer you could try this:

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

Problem

With Delphi for Windows, I usually use this code: ``` function isCtrlDown : Boolean; var ksCurrent : TKeyboardState; begin GetKeyboardState(ksCurrent); Result := ((ksCurrent[VK_CONTROL] and 128) <> 0); end; ``` How can I achieve this with FireMonkey on Mac OSX? I have found this, but I don't know how to manage it with FireMonkey/Delphi (which uses, ...): ``` 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; } ``` I'm still investigating... For now, I have find this unit with key events stuff... `unit Macapi.AppKit;`

Original source

Related problems