5

Delphi for Windowsでは、通常、次のコードを使用します。

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

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

まだ調査中です...今のところ、このユニットには重要なイベントのものがあります... unit Macapi.AppKit;

4

2 に答える 2

5

これは、現在のシフト状態を返します。

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;
于 2012-10-14T08:12:38.127 に答える
2

この回答に基づいて、これを試すことができます:

function isCtrlDown : Boolean; 
begin
    Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
end;
于 2012-10-14T07:28:57.803 に答える