- CGEventTap, .
NSMenu.
:
CGEventRef MouseClickedEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void* refcon)
{
CGPoint location = CGEventGetLocation(event);
switch (type)
{
case kCGEventLeftMouseDown:
{
NSLog(@"Left Mouse pressed at %@", NSStringFromPoint(NSPointFromCGPoint(location)));
break;
}
case kCGEventRightMouseDown:
{
NSLog(@"Right Mouse pressed at %@", NSStringFromPoint(NSPointFromCGPoint(location)));
break;
}
case kCGEventOtherMouseDown:
{
NSLog(@"Other Mouse pressed at %@", NSStringFromPoint(NSPointFromCGPoint(location)));
break;
}
default:
break;
}
return event;
}
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
CGEventMask eventMask = CGEventMaskBit(kCGEventLeftMouseDown)|CGEventMaskBit(kCGEventRightMouseDown)|CGEventMaskBit(kCGEventOtherMouseDown);
CFMachPortRef eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, 0, eventMask, MouseClickedEventCallback, NULL);
CFRunLoopSourceRef runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
}
Quartz , :
, :
- root.
- . Mac OS X v10.4, , , , .
, .
[[[NSApplication sharedApplication] currentEvent] buttonNumber] , , . , , .