現在我有一個無邊框窗口,處理鼠標下移事件來移動和調整自己的大小。但我怎樣才能處理沒有焦點的鼠標按下事件?如何讓NSWindow處理沒有焦點的mouseDown事件?
3
A
回答
6
您的自定義視圖必須實現-acceptsFirstMouse:
方法並返回YES
。
2
[NSWindow windowNumberAtPoint:mouseDownCoordinates belowWindowWithWindowNumber:0];
通mouseDownCoordinates
中,您將通過Quartz Event Services捕捉。它會返回鼠標懸停在上面的窗口號。抓住那個窗口,做你的動作/調整大小。
樣品實施(主要來自here拍攝):
#import <ApplicationServices/ApplicationServices.h>
// Required globals/ivars:
// 1) CGEventTap eventTap is an ivar or other global
// 2) NSInteger (or int) myWindowNumber is the window
// number of your borderless window
void createEventTap(void)
{
CFRunLoopSourceRef runLoopSource;
CGEventMask eventMask = NSLeftMouseDownMask; // mouseDown event
//create the event tap
eventTap = CGEventTapCreate(kCGSessionEventTap,
kCGHeadInsertEventTap, // triggers before other event taps do
kCGEventTapOptionDefault,
eventMask,
myCGEventCallback, //the callback we receive when the event fires
nil);
// Create a run loop source.
runLoopSource =
CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
// Add to the current run loop.
CFRunLoopAddSource(CFRunLoopGetCurrent(),
runLoopSource,
kCFRunLoopCommonModes);
// Enable the event tap.
CGEventTapEnable(eventTap, true);
}
//the CGEvent callback that does the heavy lifting
CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef theEvent, void *refcon)
{
// handle the event here
if([NSWindow windowNumberAtPoint:CGEventGetLocation(theEvent)
belowWindowWithWindowNumber:0] == myWindowNumber)
{
// now we know our window is the one under the cursor
}
// If you do the move/resize at this point,
// then return NULL to prevent anything else
// from responding to the event,
// otherwise return theEvent.
return theEvent;
}
相關問題
- 1. mouseDown事件沒有顯示點擊
- 2. QWidget沒有焦點事件
- 3. 爲什麼MouseDown事件處理程序沒有被擊中?
- 4. jQuery的datePicker沒有焦點事件?
- 5. 沒有失去焦點事件jQuery的
- 6. 爲處理焦點行處理onkeypress事件
- 7. 如何處理圖表部分上的mousedown事件?
- 8. 如何處理Cocoa窗口中的mousedown事件
- 9. 如何處理Windows窗體在C#中獲得焦點事件?
- 10. 如何讓Outlook處理事件更新?
- 11. 如何讓CCSprite處理Touch事件?
- 12. C#如何爲listBox1.MouseDown創建一個事件處理程序?
- 13. 如何在Flex中處理CLICK和MouseDown事件?
- 14. 使NSWindow前臺但沒有聚焦
- 15. 將mousedown事件分派給元素將不會使其焦點
- 16. 如何讓jQuery點擊事件處理角js
- 17. 如何訪問聚焦事件中的事件對象事件處理程序
- 18. jQuery如何處理點擊事件?
- 19. 失去焦點時處理鍵盤事件的最佳方式
- 20. 如何讓焦點擁有者?
- 21. 自己處理點擊鏈接 - jQuery Mousedown
- 22. 如何讓PictureBox的MouseDown事件起作用?
- 23. 的onClick沒有觸發點擊事件處理
- 24. 無法處理來自全屏的重要事件NSWindow
- 25. 無法處理從ListView項目(標籤)的MouseDown事件
- 26. 在不同的對象上處理「mousedown」事件
- 27. IE焦點事件處理程序拖延
- 28. 黑莓事件處理和焦點問題
- 29. 通過設置焦點策略處理箭頭鍵事件
- 30. jQuery/js處理與光標和事件'雙重焦點'
這不是您自己的應用程序中的窗口所必需的。你只需要實現'-acceptsFirstMouse:'就像我的答案一樣。 – 2011-03-04 04:03:48
織補。哦,希望它能幫助別人! – darvids0n 2011-03-05 13:37:18