在Cocoa应用程序中检测用户活动(轻击,点击等) [英] Detect user activity in Cocoa app (taps, clicks, ...)

查看:86
本文介绍了在Cocoa应用程序中检测用户活动(轻击,点击等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Mac应用程序,我想检测该应用程序中的用户活动,因此可以定期让Web服务知道该用户在端点上仍处于活动状态.

在Cocoa Touch中,我会覆盖UIApplicationsendEvent,但是可可中NSApplication中的sendEvent等效,

对于Mac应用程序,我应该使用哪些API来检测用户活动?也许我可以通过某种方式在全球范围内建立响应者联播,从那里可以将ping发送到我的服务?

最好,我想听用户期望每15-30秒执行一次的操作.单击,标签,键入,切换窗口或应用程序.

解决方案

您最有可能希望创建 解决方案

You most likely want to create a global event monitor using +[NSEvent addGlobalMonitorForEventsMatchingMask:handler:]. This calls your handler whenever an event whose type matches the passed mask (you should use NSAnyEventMask) is sent to another application. You can observe, but not change, the event here, which suits your usage perfectly. There is one thing to watch out for: the documentation says that you won't receive key events unless your app is trusted for Accessibility.

You can do similarly for events that are routed to your own application with +[NSEvent addLocalMonitorForEventsMatchingMask:handler:].

这篇关于在Cocoa应用程序中检测用户活动(轻击,点击等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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