UnkwnTech
UnkwnTech

Reputation: 90861

Setting monitor power state in python?

How can I send a monitor into/out-of a different power state (like sleep)?

Upvotes: 1

Views: 1259

Answers (2)

Daniel F
Daniel F

Reputation: 14239

import win32gui
import win32con

if argument == "on":
  win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND,
                       win32con.SC_MONITORPOWER, -1)

if argument == "off":
  win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND,
                       win32con.SC_MONITORPOWER, 2)

if argument == "sleep":
  win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND,
                       win32con.SC_MONITORPOWER, 1)

Upvotes: 1

BobbyShaftoe
BobbyShaftoe

Reputation: 28499

After looking at this article:

http://vbnet.mvps.org/index.html?code/screen/scmonitorpower.htm

It appears you need to send a SendMessage call similar to:

SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal MONITOR_OFF)

Although, that is a VB version. What you're really after is the WinAPI call, I'm sure you can convert this bit to however you invoke WinAPI calls in Python. I hope this helps.

Upvotes: 1

Related Questions