有条件地处理透明窗口上的鼠标事件
我正在开发一个桌面应用程序,其中我应该能够在透明窗口上获取鼠标事件。但是,透明 NSWindow 不接受鼠标事件。因此,我将 setIgnoreMouseEvents 设置为 NO,这允许透明窗口接收鼠标事件。
我在以下场景中遇到问题: 该窗口上有动态创建的矩形形状。透明窗口不应在该区域接收鼠标事件;它应该委托给该形状后面的窗口(某些其他应用程序的窗口)。 为此,如果 mouseDown 事件位于形状内部,我将 setIgnoreMouseEvents 设置为 YES。现在,如果用户在形状外部的区域中执行鼠标事件,透明窗口应该接收该事件。由于 setIgnoreMouseEvents 设置为 YES,窗口不接受鼠标事件。
无法识别 mouseDown 事件是否发生,因此我可以将 setIgnoreMouseEvents 设置为 NO。
有人可以建议我一些处理透明窗口上的鼠标事件的最佳方法吗?
迪帕
I am developing an Desktop application in which I should be able to take mouse events on transparent window. But, transparent NSWindow does not take mouse events. So, I have set setIgnoreMouseEvents to NO which allows the transparent window to take mouse events.
I have the problem in the following scenario:
There is dynamically created rectangular shape on this window. The transparent window should not take mouse events in this region; it should be delegated to the window (of some other app) that is present behind this shape.
For this purpose, if the mouseDown event is inside the shape I am setting setIgnoreMouseEvents to YES. Now, if the user performs mouse events in the area outside the shape the transparent window should take the event. Since, setIgnoreMouseEvents is set to YES, window does not take mouse events.
There is no way to identify that mouseDown event has occurred so that I can set setIgnoreMouseEvents to NO.
Could someone suggest me some best method to handle mouse events on transparent window?
Deepa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚遇到了 Quartz Event Taps,它基本上可以让您捕获鼠标事件并执行您自己的回调。
我自己还没有尝试过,但似乎您应该能够检查鼠标单击的位置并根据值有条件地执行
这是一个 示例:
I've just come across Quartz Event Taps, which basically let you capture the mouse event and execute your own callback.
Haven't tried it out myself, but it seems like you should be able to check where the mouse click fell and execute conditionally on the values
Here's an example: