pythonwindowstkintercmdscreensaver

Function notifies me that screen saver is turned on / windows


Hi so my question is: is there any function or something like that, that will notify me that the screen saver is ON and the monitor is blanked.

If there are any question out there I'm sorry, I tried to read as much as i could


Solution

  • In C++ there is a function called SystemParametersInfo that let you check is screensaver running or not. So you can create exe in C++ that will check for screensaver and return result, and then you may execute it from python and check for result.

    isScreensaverRunning.cpp

    #include <Windows.h>
    int main(){
        BOOL running;
        SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
        return running;
    }
    

    isScreensaverRunning.py:

    import os
    isRunning= os.system("C:\\src\\isScreensaverRunning\\isScreensaverRunning.exe");
    if( isRunning!=0 ):
       ...
    

    You also mentioned that you just want to shutdown your computer 2 hours after starting screensaver. In Windows7 Power Saving Settings there is an option to put computer to Sleep or Hibernate after some time of inactivity.