Macks
Macks

Reputation: 1776

How do I change my cursor on the whole screen? (not only current view/window)

I'm currently learning objective c and I'm trying to write some simple apps to help me learn. Right now, I'm trying to make an app that lets me measure a certain area anywhere on the screen. (similar to this: https://addons.mozilla.org/de/firefox/addon/measureit/)

For that to work, I need to know how I can change my cursor anywhere on the screen, Not only within a certain window (I already got that to work).

Currently I have a class called "MyCustomView" that is assigned to my main window view. I implemented the resetCursorRects-method like this:

- (void) resetCursorRects {
    [super resetCursorRects];

    NSCursor *myCursor = [NSCursor crosshairCursor];
    CGRect screenRect = [[NSScreen mainScreen] frame];
    [self addCursorRect:screenRect cursor:myCursor];
}

It successfully changes my cursor to crosshair, but only within the current window. I want my cursor to change for all of the screen. How can I accomplish this?

Thank you for your help, guys!

Upvotes: 1

Views: 605

Answers (1)

Remizorrr
Remizorrr

Reputation: 2322

You can create NSCursor instance and then invoke set method

[[[NSCursor alloc] initWithImage:[NSImage imageNamed:@"myCursor.png"] hotSpot:NSZeroPoint] set]

But other windows will change it, so i think you need a Window with 0.0 opacity overlaying all screen.

You can do it by setting window level. [window setLevel:NSScreenSaverWindowLevel]

Upvotes: 1

Related Questions