如何编写即使未激活也会影响更改(自定义光标,绘制图像)的OS X应用程序? [英] How to write an OS X application that can effect changes (custom cursor, draw an image) even when it is not active?

查看:66
本文介绍了如何编写即使未激活也会影响更改(自定义光标,绘制图像)的OS X应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前曾问过一个有关在OSX上更改系统游标的问题.我使用NSCursor更改了光标,但是效果只有在应用程序处于活动状态时才有效.当另一个应用程序变为活动状态时,自定义光标将丢失.

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?

我知道我可能需要比Cocoa API更低的水平.我只是不知道从哪里开始寻找?我需要查看任何特定的Carbon API?甚至更低?

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?

谢谢!

推荐答案

您可以实现所需的效果,但不能达到您正在考虑的方式.

You can achieve the effect you want, but not the way you're thinking about doing it.

你说,

我正在编写一个演示辅助应用程序,该程序以编程方式在屏幕上显示激光指示器"的等效内容.我的第一个想法是使用鼠标光标本身作为指针,并将其外观更改为红色圆圈.

I am writing a presentation aid application that shows the equivalent of the "laser pointer" on screen, programmatically. My first idea was to use the mouse cursor itself as the pointer, and change its appearance as a red circle.

然后伪造那个.创建一个应用程序,可能类型为 LSUIElement ,也许不是,取决于您想要的行为.创建一个无边界窗口(类型为 NSBorderlessWindowMask ),然后将其填充为透明颜色.将其窗口级别设置得足够高,以使其浮动在所有内容上(使用-[NSWindow setLevel:] ,尽管我无法想到最好的级别是什么),然后将其绘制

Then fake that. Create an application, perhaps of type LSUIElement, perhaps not, depending on the behavior you want. Create a borderless window (type NSBorderlessWindowMask) 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.

这篇关于如何编写即使未激活也会影响更改(自定义光标,绘制图像)的OS X应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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