开发者

Custom NSCursor does not hold for all applications

开发者 https://www.devze.com 2023-03-26 04:12 出处:网络
I have written a Cocoa program to change the cursor after a button press. Specifically, the cursor includes an image instead of a pointer. I set it using the following commands:

I have written a Cocoa program to change the cursor after a button press. Specifically, the cursor includes an image instead of a pointer. I set it using the following commands:

NSImage *tmpImage = [NSImage imageNamed:@"pointer"];
NSCursor *pointer = [[NSCursor alloc] initWithImage:tmpImage hotSpot:NSMakePoint(10.0, 10.0)];
[pointer set];

This works and the cursor changes correctly. However, this change does not hold for all applications. For example, when I switch to a Keynote presentation in Slideshow mode, the cursor changes back to the arrow. When I switch to the PDF full-screen display for a presentation, the cursor changes to a hand (I believe these are the default cursors set by the respective applications).

My question is: Is there any way to override those and just keep my custom cursor for all applications? I would like to keep my changed cursor even during a Keynote sl开发者_如何学JAVAideshow and a PDF full-screen view. Any ideas?

Thanks!


It is not possible to change the cursor for other applications, at least not using public API.

The only way to do this is to create a custom non-bordered window, which will only show the image of the cursor, then use CoreGraphics API to hide the cursor and simply move the window around as the mouse moves. This is aproximately how Apple's doing the large cursor that can be turned on in the Accessibility system preferences.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号