Getting “global” mouse position in Mac OS X

前端 未结 5 454
醉话见心
醉话见心 2020-12-24 02:41

How can I get in Mac OS X \"global\" mouse position - I mean how can I in cocoa/cf/whatever find out cursor position even if it\'s outside the window, and even if my window

5条回答
  •  一个人的身影
    2020-12-24 03:35

    NSPoint mouseLoc;
    mouseLoc = [NSEvent mouseLocation]; //get current mouse position
    NSLog(@"Mouse location: %f %f", mouseLoc.x, mouseLoc.y);
    

    If you want it to continuously get the coordinates then make sure you have an NSTimer or something similar

提交回复
热议问题