我剛剛碰到石英事件絲錐,這基本上讓你捕獲鼠標事件和執行自己的回調。
還沒有嘗試過了自己,但好像你應該能夠檢查在鼠標點擊下跌和值
這裏有條件的執行是一個example:中
//---------------------------------------------------------------------------
CGEventRef MouseTapCallback(CGEventTapProxy aProxy, CGEventType aType, CGEventRef aEvent, void* aRefcon)
//---------------------------------------------------------------------------
{
if(aType == kCGEventRightMouseDown) NSLog(@"down");
else if(aType == kCGEventRightMouseUp) NSLog(@"up");
else NSLog(@"other");
CGPoint theLocation = CGEventGetLocation(aEvent);
NSLog(@"location x: %d y:%d", theLocation.x, theLocation.y);
return aEvent;
}
//---------------------------------------------------------------------------
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//---------------------------------------------------------------------------
{
CGEventMask theEventMask = CGEventMaskBit(kCGEventRightMouseDown) |
CGEventMaskBit(kCGEventRightMouseUp);
CFMachPortRef theEventTap = CGEventTapCreate(kCGSessionEventTap,
kCGHeadInsertEventTap,
0,
theEventMask,
MouseTapCallback,
NULL);
if(!theEventTap)
{
NSLog(@"Failed to create event tap!");
}
CFRunLoopSourceRef theRunLoopSource =
CFMachPortCreateRunLoopSource(kCFAllocatorDefault, theEventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
theRunLoopSource,
kCFRunLoopCommonModes);
CGEventTapEnable(theEventTap, true);
}
可能重複[如何使用非矩形按鈕創建透明窗口?](http://stackoverflow.com/questions/1527907/how-to-create-a-transparent-window-with-non-rectangular-buttons) – Ben 2012-06-21 10:14:11
The magic你正在尋找的詞是「命中測試」。這就是窗口如何配合確定鼠標是否應該被視爲在窗口之上的過程。 – Ben 2012-06-21 10:15:27
我建議你只爲該矩形創建一個跟蹤區域,並從視圖中的響應者鏈中截取,然後將其委派給想要捕獲所需事件的窗口。 – Arvin 2013-03-12 05:04:22