views:

118

answers:

1

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 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

+1  A: 

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.

Nikolai Ruhe
This is a good idea, thanks, but i'm searching for an easier way to do this.Windows give me the "IsSystemResumeAutomatic-Function", to get the information. Is there a comparable function for mac?
Nobik