本文介绍了Mac OS X上,检测用户活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用功能IOPMSchedulePowerEvent安排休眠或唤醒活动并注册我与IORegisterForSystemPower守护进程来接收电源状态的改变。一切正常!

I use the function "IOPMSchedulePowerEvent" to schedule Sleep or Wake-Events and registered my daemon with "IORegisterForSystemPower" to receive power-state-changes. Everything works fine!

当系统去睡觉,后来在预定的时间醒来,我的守护进程做一些工作,之后系统应该再次去睡觉。

When system going sleep and later waking up at scheduled time, my daemon do some work, and after it system should going sleep again.

现在我的问题:


  1. 我如何可以检测,如果系统被用户或预定的时间醒了?

  1. How can i detect, if the system was awaked by user or by the scheduled time?

我如何可以检测,如果用户目前与系统工作,所以守护进程还没有把它在休眠模式???

How can i detect, if a user currently working with the system, so the daemon have not to put it in sleep-mode???

谢谢
Nobik

ThanksNobik

推荐答案

有检测各种形式的用户交互的一个简单的方法:使用 CGEventSourceCounterForEventType 可以查询自开机的时候键盘presses或鼠标移动的数量。通过定期执行此操作并比较计数,可以检测的相互作用。

There's an easy way to detect various forms of user interaction: Using CGEventSourceCounterForEventType you can query the number of keyboard presses or mouse moves since boot time. By doing this at regular intervals and comparing the counts, you can detect interaction.

这篇关于Mac OS X上,检测用户活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:32