How to detect current system cursor on OSX?

1.1k views Asked by At

Is there a way to know what the current system cursor on mac/ OSX is ? I know we can get current cursor using [NSCursor currentSystemCursor] call. But this does not tell us what the current cursor is. The check if ([[NSCursor currentSystemCursor] isEqual:[NSCursor arrowCursor]]) always fails. Even the check if ([[NSCursor currentSystemCursor] isEqual:[NSCursor currentSystemCursor]]) always returns zero.

I have gone through similar question How to get current type of mouse cursor in Mac OS X? but did not find any way of doing it there.

Any help on this is appreciated. Thanks in advance.

2

There are 2 answers

0
Nick Moore On

Unfortunately not.

What you can do is get the cursor image and the compare that image to the image of a known cursor (arrow, I-beam, etc).

However many apps supply slight variations of each cursor so your check can never be exhaustive unless you keep updating the app to know about more and more cursor variation.

You can even build an algorithm to analyse the cursor image to heuristically categorise it.

It sounds hacky, I know. But it does work. Kinda.

0
Joe Susnick On

I was able to get this to work using double equals.

ex:

[NSCursor currentCursor] == [NSCursor arrowCursor]

returns the result I'm expecting. It's annoying that you can't just query the type but at least this worked to set conditional breakpoints and stuff like that.

Hope that helps.