How to determine that a screensaver is running?

我与影子孤独终老i 提交于 2019-12-01 06:22:01

I think the key is to identify the screensaver by its window class ("WindowsScreenSaverClass"). I found this page How do I start, detect and stop screen savers? that has some code examples and explanations.

See the WINAPI function SystemParametersInfo() with the SPI_GETSCREENSAVERRUNNING parameter. It's the only documented way to detect whether the screen saver is currently running. (You can also find out if a screen saver is even enabled, get and set the timeout value, and start the screen saver using this function.)

HOW TO: Determine If Screen Saver Is Running by Using Visual Basic 6.0

I know this is for VB6, but it's bound to be a good place to start.

krizajb

This is my implementation of screen saver event detection.

Notes:

  • SPI_GETSCREENSAVERRUNNING detects Windows Event id 4802 and 4803 which weren't accurate in my case, see my problem hence user idle time calculation is added
  • GetLastInputInfo apparently doesn't work if process is a service.

search processes for a process with .scr in its .MainModule.FileName

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!