How to detect desktop idle time from an Electron app?

前端 未结 4 1032
情话喂你
情话喂你 2021-02-06 10:01

I need my Electron app to respond to the user becoming idle (no mouse or keyboard inputs to any program on the OS) for a certain amount of time.

How can I trigger a func

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 10:29

    You can always detect idle times on Linux by using XScreenServer, GetLastInputInfo on Windows and CGEventSourceSecondsSinceLastEventType on Mac

    I've published desktop-idle using these API's, you can check the source code https://github.com/bithavoc/node-desktop-idle

    UPDATE:

    Electron 3 users can use the power monitor API to achieve the same goal: https://electronjs.org/docs/api/power-monitor

提交回复
热议问题