Question

It's the magnifier glass at the top left:

I've tried 2 methods, but both failed.

  1. Once the magnifier glass is clicked, create a new cursor(a cursor with magnifier glass image, or a crossfair, whatever) and push it, then call nextEventMatchingMask:untilDate:inMode:dequeue: of NSApplication to eat all the events until we get a NSLeftMouseUp event. It did works but not perfectly, other windows or apps will be ordered front when the click point is out of the origin window.

  2. Create a NSColorPanel, try to send a fake mouse click event to the panel. It works on the color wheel, but has no effect once I change the event location to the magnifier glass button.

Question in [1]: How could I forbid all system mouse events dispatching until user clicks the left button?

Question in [2]: Is this possible?

Thanks for any response.

Was it helpful?

Solution

Quartz events service could be used if we want to block system events dispatching, but there are 2 problems with it:

  1. Accessibility should be enabled by user;
  2. Quartz event service is forbidden under sandbox.

It's impossible to make the method 1 succeeded.

Inspired by @CodaFi, I decided to use subclass of NSWindow to implement it. A sample project is created at gitbub https://github.com/wentingliu/ScreenPicker, go and check it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top