如何强制NSWindow总是活动/聚焦? [英] How to force an NSWindow to be always active/focused?

查看:231
本文介绍了如何强制NSWindow总是活动/聚焦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个透明的 NSWindow ,在用户的屏幕上随处可见( NSWindow 应用程序,无论什么,甚至全屏应用程序)。

NSWindow 我有一个 mouseDown 事件,显示一个弹出窗口。让我们说我在safari全屏模式,我有我的窗口在它的前面,我点击safari,我再次点击我的窗口:没有发生,mouseDown不发生。我必须再次点击,以便触发 mouseDown 事件。

如何强制我的 NSWindow 始终处于活动状态,所以当我点击后台应用程序并点击我的窗口时,我不必点击它来触发 mouseDown

谢谢!

I have a transparent NSWindow that follows the user's screen everywhere he goes (the NSWindowstays in front of every app, no matter what, even fullscreen apps).
In that NSWindow i have a mouseDown event that shows a popup. Let's say i'm on safari in fullscreen mode and i have my Window in front of it, i click on safari and i click again on my Window: nothing happens, the mouseDown doesn't occur. I have to click again so the mouseDown event is triggered.
How can i force my NSWindow to be always active so i don't have to click it 2x to trigger the mouseDown when i click on a background app and click in my window again?
Thank you!

推荐答案

如果您在窗口视图中添加无边框NSButton实例,作为按钮的图像(以及作为其替代图像,使其更漂亮),它将开箱即用:只需将按钮的动作方法连接到您的应用程序委托(或您要处理的单击动作的对象)。点击图片(即按钮)将触发按钮的操作方法,无论哪个窗口处于活动状态。

If you add a borderless NSButton instance to your window's view and set your image as the button's image (and as its alternate image, to make it more beautiful), it will work out of the box: Just connect the button's action method to your app delegate (or the object where you want to process the click action). A click on the image (i.e. the button) will then trigger the button's action method, no matter which window is active.

这篇关于如何强制NSWindow总是活动/聚焦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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