获取“全局"信息在Mac OS X中的鼠标位置 [英] Getting "global" mouse position in Mac OS X

查看:145
本文介绍了获取“全局"信息在Mac OS X中的鼠标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Mac OS X中获得全局"鼠标位置-我的意思是如何在cocoa/cf/中找到光标位置,即使它在窗口之外,并且即使我的窗口处于非活动状态也是如此?

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 is inactive?

我知道这是有可能的(即使没有管理员权限),因为我已经在Java中看到过类似的东西-但我想在ObjC中编写

I know it's somehow possible (even without admin permissions), because I've seen something like that in Java - but I want to write it in ObjC

对不起,我的英语-希望您能理解我的意思;)

Sorry for my English - I hope you'll understand what I mean ;)

推荐答案

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

如果您希望它不断获取坐标,请确保您有一个NSTimer或类似的东西

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

这篇关于获取“全局"信息在Mac OS X中的鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆