2012-10-13 12 views
5

Z Delphi dla Windows, Zwykle używam tego kodu:Jak uzyskać aktualne stany modyfikujące za pomocą FireMonkey na OSX?

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

W jaki sposób można to osiągnąć z FireMonkey na Mac OSX?

znalazłem this, ale nie wiem, jak zarządzać go FireMonkey/Delphi (który używa, ...):

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; 
} 

ja nadal bada ... Dla teraz muszę znaleźć tę jednostkę z kluczowych wydarzeń rzeczy ... unit Macapi.AppKit;

Odpowiedz

2

podstawie tej answer można spróbować to:

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

ta zwraca aktualny stan Shift:

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; 
+0

Oba rozwiązania zamieszczone w czasie snu pracują. Przepraszam, zaakceptowałem drugi, ponieważ został opublikowany kilka minut wcześniej ... trudno było wybrać między wami oboje. BTW, dostajesz +1 – Whiler

+0

dzięki Whiler, +1 ode mnie też Giel –

Powiązane problemy