我该如何“冻结"?与其他窗口的所有交互? [英] How can i "freeze" all interaction with other windows?

查看:112
本文介绍了我该如何“冻结"?与其他窗口的所有交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎有点奇怪.基本上,我正在尝试制作菜单栏应用程序.当用户按下命令时,我要这样做,以便您无法与其他正在运行的应用程序进行交互(写/选择/单击等).

This question might seem kind of odd. Basically I'm trying to make a menubar application. When the user presses command, I want to make so that you can't interact with other apps running (write/select/click etc).

我正在使用此代码来检测是否按下了命令和鼠标按钮:

Im using this code to detect if command and mouse button is pressed:

mouseEventMonitor = [NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask ) {
         if (event.modifierFlags & NSCommandKeyMask)
                                                                       { 
    // "Freeze" all other apps.
    }
    }];

但是,当我在桌面上使用它时,可以找到它,但是,在safari或xcode中使用此xcode会导致巨大的滞后,因为它们与我的应用程序冲突.我还尝试在此后面添加一个不可见的窗口.但是,当我这样做时,mouseEventMonitor将不起作用,因为它仅适用于应用程序外部的事件.

When I use this on the desktop it works find, however, using this xcode in safari or xcode causes huge lag because they conflict with my app. I also tried adding a invisible window behind this. But, when I did so the mouseEventMonitor will not work because it only work for events outside of the app.

我希望我对此解释得足够好.

I hope i explained this well enough.

干杯.

推荐答案

我不是很了解您的问题,但是对于不可见的背景窗口(在您的应用程序内部),您可以尝试使用LocalMonitor代替GlobalMonitor:

I am don't really understand your question, but for invisible background window (inside your app) you can try use LocalMonitor instead GlobalMonitor:

mouseEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:(NSLeftMouseDownMask | NSRightMouseDownMask | NSOtherMouseDownMask) handler:^NSEvent *(NSEvent *event) {


NSLog(@"theEvent->%@",event);

return event;
}];

这篇关于我该如何“冻结"?与其他窗口的所有交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆