I would like to make a custom panel, that shows a zoom at the current cursor-location. Like for example 'Sip' does. I have searched the web for examples, but didn't find anything specific.

I found NSEvent's addGlobalMonitorForEventsMatchingMask:handler: and addLocalMonitorForEventsMatchingMask:handler: methods. Now I could just set the frame origin of the window. But I'm not sure if that's really the right solution.

Is there a better way to do this? Could anyone point me into some sample-code?

有帮助吗?

解决方案

That's basically it.

You can also use the Quartz Event Tap function family CGEventTap, as it will provide a little more responsiveness during events like the Mac application switcher and Exposé or Mission Control or Dashboard. However, it is a little harder to set up, and uses a C callback approach that is a little tougher to use with some things.

Quartz Event Taps are otherwise the same thing, but possibly slightly faster.

If you use that, be sure to use the function CGPoint CGEventGetUnflippedLocation(CGEventRef aCGEvent)

As in: CGPoint eventLocation = CGEventGetUnflippedLocation(aCGEvent);

That will make sure your y coordinates are bottom left like the rest of Cocoa. Otherwise use its sibling CGEventGetLocation() which for some odd reason of crappy naming doesn't indicate that it returns flipped coordinates. (but the docs do state this)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top