0

I'm really a beginner in python and wanted to know on how can I use Power Setting GUIDs to get the status for monitor and display in python. I already visited this link but it is too complex for me as I just wanted to get a one line sentence saying Monitor on or Display on. Hope anyone can provide guidance to me in python.

Thank you.

iyzad
  • 81
  • 2
  • 2
  • 10

1 Answers1

0

I suggest you have a try the code showed in the link you mentioned. I test on Window 10 with Python 3.6, it works perfectly.

Before you run the code you may need to install two modules like this:

pip install pypiwin32

pip install comtypes

After that open the Python code file via Python IDE and select Run module from the menu bar. You will get the following output:

*** STARTING ***
hwnd: 67998
registering GUID_MONITOR_POWER_ON
result: -0x5438e940
lastError: 0

registering GUID_SYSTEM_AWAYMODE
result: -0x5438e780
lastError: 0

registering GUID_CONSOLE_DISPLAY_STATE
result: -0x5438ea20
lastError: 0

registering GUID_ACDC_POWER_SOURCE
result: -0x5438eb00
lastError: 0

registering GUID_BATTERY_PERCENTAGE_REMAINING
result: -0x5438e6a0
lastError: 0


Entering loop
Power setting changed...
Monitor on
Power setting changed...
Display on
Power setting changed...
AC power
Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • yes I know and already run the code, but i can't seems to retrieved only the information for "Monitor on" and "Display on" it keeps looping. Do you have any idea on how can I get it? because I need to trigger something depending on only the monitor and display status. – iyzad Dec 14 '18 at 08:49
  • Hi iyzad, from the documents([1](https://learn.microsoft.com/en-us/windows/desktop/Power/power-setting-guids),[2](https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registerpowersettingnotification),[3](https://learn.microsoft.com/en-us/windows/desktop/Power/registering-for-power-events)) it seems to be designed to working on this way: waiting for the system send the message to the application and handle the message. Maybe you can use Multithreaded Programming in python: one thread for monitoring the state of the display and the other thread do something you want. – Rita Han Dec 14 '18 at 09:50
  • Hi iyzad, for multi-threading in Python you can reference [this thread](https://stackoverflow.com/questions/47428768/parallel-multiprocessing-in-python-easy-example?rq=1) for a simple sample. – Rita Han Dec 17 '18 at 05:34