检测 macOS 上的用户活动

发布于 2024-09-03 05:04:50 字数 299 浏览 4 评论 0原文

我使用函数“IOPMSchedulePowerEvent”来安排睡眠或唤醒事件,并使用“IORegisterForSystemPower”注册我的守护程序以接收电源状态更改。一切正常!

当系统进入睡眠状态并稍后在预定时间醒来时,我的守护进程会执行一些工作,之后系统应该再次进入睡眠状态。

现在我的问题是:

  1. 我如何检测系统是否被用户唤醒或按预定时间唤醒?

  2. 我如何检测,如果用户当前正在使用系统,那么守护进程不必将其置于睡眠模式???

谢谢 诺比克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远昼 2024-09-10 05:04:50

有一种简单的方法可以检测各种形式的用户交互:使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文