检测 macOS 上的用户活动
我使用函数“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.
Now my questions:
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???
Thanks
Nobik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一种简单的方法可以检测各种形式的用户交互:使用
CGEventSourceCounterForEventType
您可以查询自开机以来键盘按下或鼠标移动的次数。通过定期执行此操作并比较计数,您可以检测交互。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.