如何编写一个即使在不活动的情况下也能实现更改(自定义光标、绘制图像)的 OS X 应用程序?
我之前问过一个关于在 OSX 系统范围内更改光标的问题。我使用 NSCursor 来更改光标,但效果仅在应用程序处于活动状态时有效。当另一个应用程序处于活动状态时,自定义光标就会丢失。
这是一个相关的、更普遍的问题。如何编写具有系统妻子效果的应用程序?例如,即使您的应用程序未处于活动状态,而其他东西处于活动状态,也要在屏幕上绘制图像?
我知道我可能需要进入比 Cocoa API 更低的级别。我只是不知道从哪里开始寻找?我需要查看任何特定的 Carbon API 吗?甚至更低?
任何指示将不胜感激!如果您特别知道如何在系统范围内更改光标或如何绘制图像并移动它(无论哪个应用程序处于活动状态),那也可以解决我当前的问题!我可以编写一个应用程序,当它安装在系统上时可以实现此目的吗?
谢谢!
I previously asked a question about changing the cursor system-wide on OSX. I used NSCursor to change the cursor, but the effects are only as long as the application is active. When another application becomes active, the custom cursor is lost.
Here is a related, more general question. How can you write an application to have system-wife effects? For example drawing an image on-screen even when your application is not active, and something else is?
I understand I probably need to go at a lower level than the Cocoa APIs. I just cannot figure out where to start looking? Any specific Carbon APIs that I need to be looking at? Or even lower?
Any pointers would be appreciated! If you specifically know how to change the cursor system-wide or how to draw an image and move it around (no matter what application is active), that would solve my current problem as well! Can I write an application that can achieve this when its installed on the system?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以实现您想要的效果,但无法实现您想要的方式。
你说,
然后假装那个。创建一个应用程序,可能是
LSUIElement
类型,也可能不是,具体取决于您想要的行为。创建一个无边框窗口(输入NSBorderlessWindowMask
)并用透明颜色填充它。将其窗口级别设置得足够高,以便它漂浮在所有内容上(使用-[NSWindow setLevel:]
,尽管我无法立即想到最好的级别),然后绘制到其中。确实,当您不是最重要的应用程序时,您无法设置光标。确实,你不能只在屏幕上乱写乱画。但如果你够聪明,你也能得到同样的效果。
You can achieve the effect you want, but not the way you're thinking about doing it.
You say,
Then fake that. Create an application, perhaps of type
LSUIElement
, perhaps not, depending on the behavior you want. Create a borderless window (typeNSBorderlessWindowMask
) and fill it with a clear color. Set its window level high enough so that it floats over everything (using-[NSWindow setLevel:]
, though I can't think of what the best level would be off-hand), and draw into it.It's true that you cannot set the cursor when you are not the foremost app. It's true that you cannot just scribble on the screen. But you can get the same effects if you're clever.
Mac OS X 上的任何 API 均不提供此行为。您必须修改操作系统中的资源文件,这是一个非常危险的操作,可能会使目标计算机变砖。你必须知道你在做什么。
您是否正在尝试实现主题应用程序或类似的东西?你的目标是什么?如果您告诉我们您想做什么,我们也许可以建议替代方法。
This behaviour is not provided by any APIs on Mac OS X. You would have to modify the resource files in the OS, and that's a very dangerous operation that could brick the target computer. You have to know what you're doing.
Are you trying to implement a theming app or something like that? What's your goal? If you tell us what you are trying to do, we may be able to suggest alternate approaches.