How to change the size of the system cursor in a macosx cocoa app programmatically using swift or objective-c?

╄→гoц情女王★ 提交于 2019-12-05 20:16:06
CGError state = CGSShowCursor(CGSDefaultConnection) ;
    if (state != kCGErrorSuccess) NSLOG(@"error : %d",state);

maybe try it with CGSShowCursor(CGSMainConnectionID())

This might also help : https://github.com/alexzielenski/Mousecape/blob/1d534b1e076b07a01b80364be23c88c8439028bc/Mousecape/mousecloak/NSCursor_Private.h

Warning. This code is not based on what is saved in preferences so combine it:

  float cursorScale = 2;
  cursorScale = MAX(1, MIN(cursorScale,4));
  int connectionID = CGSMainConnectionID();
  CGSSetCursorScale(connectionID, cursorScale);

to get the size

  CGSGetCursorScale(connectionID, &cursorScale);

,

   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   NSDictionary *olddict = [defaults persistentDomainForName:@"com.apple.universalaccess"];
   NSMutableDictionary *newdict = [olddict mutableCopy];
   [newdict setObject:@4.0 forKey:@"mouseDriverCursorSize"];
   [defaults setPersistentDomain:newdict forName:@"com.apple.universalaccess"];
   [defaults synchronize];
   NSLog(@"Cursor size set to %@", newdict);

CREDITS: Alex Zielenski

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!