2012-10-13 21 views
5

隨着德爾福適用於Windows,我通常使用此代碼:如何在OSX上使用FireMonkey獲取當前修飾符狀態?

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

我怎樣才能用FireMonkey在Mac OSX上實現這一目標?

我發現this,但我不知道如何與FireMonkey /德爾福對其進行管理(使用,...):

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;

回答

2

在此基礎上answer你可以試試這個:

function isCtrlDown : Boolean; 
begin 
    Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask; 
end; 
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; 
+0

我睡覺時貼正在這兩個解決方案。對不起,我已經接受了另一個,因爲它幾分鐘前發佈了......你很難在兩者之間做出選擇。順便說一句,你得到+1 – Whiler

+0

謝謝Whiler,從我+1也Giel –

相關問題