Python "monitor on" by sendmessage doesn't work

Viewed 29

Here my code, which should turns monitor on and off. turns_off work, but when I call turns_on, when the monitor off, my diode from power button on monitor just lighting for few milliseconds, and nothing else (Of course it prints "Monitor turned on"). I still can turns monitor on by mouse movement.

import win32gui
import win32con


class Monitor:

    @staticmethod
    def turns_on():
        print("Monitor turned on")
        win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, win32con.SC_MONITORPOWER, -1)

    @staticmethod
    def turns_off():
        print("Monitor turned off")
        win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, win32con.SC_MONITORPOWER, 2)

EDITED

P.S. I've read, that SendMessage is blocking program, so I've replaced them to PostMessage, but problem is still actual.

class Monitor:

    @staticmethod
    def turns_on():
        print("Monitor turned on")
        win32gui.PostMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, win32con.SC_MONITORPOWER, -1)

    @staticmethod
    def turns_off():
        print("Monitor turned off")
        win32gui.PostMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, win32con.SC_MONITORPOWER, 2)
0 Answers
Related