[python-win32] turning monitors off from Python?

Tim Golden mail at timgolden.me.uk
Thu Dec 4 11:09:35 CET 2008


Alec Bennett wrote:
> I'm trying to turn a monitor off from a Python script. I can do this using the program "wizmo", so its possible from Windows. I found this script which describes a method using SendMessage:
> 
> http://fci-h.blogspot.com/2007/03/turn-off-your-monitor-via-code-c.html
> 
> Translated to Python, here's what I have so far:
> 
> SC_MONITORPOWER = 0xF170
> win32gui.SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
> 
> That follows this general structure:
> SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal MONITOR_OFF)
> 
> My problem is getting the handle. 

The article you mention suggests using the desktop window handle --
available via GetDesktopWindow (). You might try that?


TJG


More information about the python-win32 mailing list