鼠标跟踪守护进程 [英] Mouse tracking daemon

查看:29
本文介绍了鼠标跟踪守护进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Cocoa 编写一些内容来显示原始鼠标移动数据.最理想的情况是,该应用程序只是一个运行的小守护程序,将数据传递到套接字服务器,另一个应用程序可以利用该服务器来访问事件.

I need to write something using Cocoa to surface raw mouse movement data. Optimally, the app would just be a little daemon that would run, passing the data to a socket server which another application could tap into to gain access to the events.

有人能在方法和工具方面为我指出正确的方向吗?我现在什至不知道从哪里开始.

Can anyone point me in the right direction with regard to approach and tools? I am not even sure where to begin with this right now.

推荐答案

另一种简单的方法是 添加全局事件监视器(但仅适用于 10.6):

The other simple way to do this is to add a global event monitor (10.6 only, however):

id eventHandler = [NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent * mouseEvent) {
  NSLog(@"Mouse moved: %@", NSStringFromPoint([mouseEvent locationInWindow]));
}];

然后,当您完成跟踪后,您可以:

Then when you're done tracking, you do:

[NSEvent removeMonitor:eventHandler];

这篇关于鼠标跟踪守护进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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