保持另一个应用程序的窗口处于活动状态,同时仍然从另一个应用程序的窗口接收鼠标事件?
有没有办法让我的应用程序的窗口接收键盘和/或鼠标事件(即用户单击窗口的按钮),同时仍将焦点保留在另一个不相关的应用程序上?
我尝试在不同级别配置我的窗口,包括 [myWindow setLevel:NSPopUpMenuWindowLevel] 但无济于事。
Is there a way to have my app's window receive keyboard and/or mouse events (i.e. user clicking on window's buttons) while still retaining focus to another, unrelated app?
I've tried configuring my window at different levels, including [myWindow setLevel:NSPopUpMenuWindowLevel] to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够通过使视图(至少是处理鼠标单击的视图)响应
acceptsFirstMouse:
消息通过发送NSApp
一条preventWindowOrdering
消息,然后返回YES
。你不应该让你的应用程序在没有在前面排序的情况下处理输入。如果出现的字段被另一个窗口遮挡,用户可能不会意识到他们的输入将转到哪里。
You should be able to handle mouse clicks without ordering your window front by making your views (at least the ones that handle mouse clicks) respond to
acceptsFirstMouse:
messages by sendingNSApp
apreventWindowOrdering
message and then returningYES
.You should not make your app handle typing without ordering itself front. The user might not realize where their typing is going if the field where it's appearing is obscured by another window.
找到了。简单,却又难以捉摸。
使用 NSPanel 并确保面板样式为非激活 (NSNonactivatingPanelMask) 或在 IB 的检查器中勾选相同的选项。
Found it. Simple, yet elusive.
Use NSPanel and make sure panel style is Non Activating (NSNonactivatingPanelMask) or tick the same option in IB's inspector.