11

Is there a way to globally hide the mouse cursor for all apps in Cocoa (or Carbon)? Or at least replace it with something else?

EDIT: Thanks for the input guys, but turns out Daniel Jalkut found the solution a while ago :) http://lists.apple.com/archives/carbon-dev/2006/Jan/msg00555.html

  • Care to explain a little more as to why you'd want to do this? It generally seems a bad idea as you'd lose the advantage of the cursor changing as items are moused over. Or are you intending more to skin the cursor? i.e. still have it change on mouse over, but again to a custom cursor – Mike Abdullah Sep 11 '09 at 22:10

4 Answers4

9

You are looking for CGDisplayHideCursor, which is part of the Quartz Display Services API.

0xced
  • 25,219
  • 10
  • 103
  • 255
  • Thanks, didn't see that before. "In most cases, the caller must be the foreground application to affect the cursor." So...what's the case where I *don't* have to be the foreground application? :) –  Oct 03 '09 at 20:59
  • I came here searching for a way to hide the cursor in my foreground application only, and this was exactly the ticket. Thanks! – e.James Apr 28 '10 at 03:39
  • It seems the link in the answer is defunct now but can be found at: https://developer.apple.com/documentation/coregraphics/1456534-cgdisplayhidecursor. When using Swift, I had to use `CGDisplayHideCursor(CGMainDisplayID())` as `kCGDirectMainDisplay` doesn't appear to be available. – Todd Apr 26 '19 at 09:18
3

Check out: http://developer.apple.com/legacy/mac/library/samplecode/CarbonCocoa_PictureCursor/listing2.html It's an old sample, but probably still works.

I expect that you're going to be limited to your application window, however. If you want to hide it for everyone you will probably have to make your window cover the screen.

Fun fact: The old toolbox function was simply "HideCursor()".

Seth
  • 45,033
  • 10
  • 85
  • 120
  • Thanks. Any advice on making a window cover my screen? (To be clear, I want the mouse cursor to hide for all applications as well...) –  Sep 12 '09 at 19:09
  • Handling a full screen window the right way means you'll have to make sure you're covering all attached screens. Look at: http://www.cocoadevcentral.com/articles/000028.php. Alternatively, you might find some sample code for a screen saver application. Screen savers generally cover the screen as well. In your case, you'll want to modify your window to be a layer below your application windows. – Seth Sep 19 '09 at 17:40
3

just add this to your code:

CGDisplayHideCursor (kCGNullDirectDisplay);
Jesus
  • 8,456
  • 4
  • 28
  • 40
0

No, I don't believe there's a way of doing what you want, short of showing a full screen window and then obscuring absolutely everything on the desktop. That would also prevent e.g. keystrokes being sent to the right application and the like.

AlBlue
  • 23,254
  • 14
  • 71
  • 91