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:
How can i detect, if the system was awaked by user or by the 开发者_C百科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???
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.
精彩评论