1

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.

4

1 回答 1

3

如果我们想阻止系统事件调度,可以使用 Quartz 事件服务,但它有两个问题:

  1. 应由用户启用可访问性;
  2. 沙盒下禁止 Quartz 事件服务。

方法1是不可能成功的。

受@CodaFi 的启发,我决定使用 NSWindow 的子类来实现它。在 gitbub https://github.com/wentingliu/ScreenPicker创建了一个示例项目,去看看吧。

于 2013-03-30T08:51:21.210 回答