开发者

Detecting user-activity on mac os x

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.

Now my questions:

  1. How can i detect, if the system was awaked by user or by the 开发者_C百科scheduled time?

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

Thanks Nobik


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜