turn monitor off and on

A

Astan Chee

Hi,
I'm trying to turn off my monitor, pause and then turn it on again.
I'm doing this in python 2.6 and windows xp. Here is my script so far
(that doesn't work):

import time
import win32gui
import win32con
import win32api

def turnOffMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2)

def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)

if __name__ == "__main__":
turnOffMonitor()
time.sleep(5)
turnOnMonitor()

For some reason, the script doesn't turn the monitor back on. What am
I doing wrong here or are there any other alternative?
 
H

harrismh777

Astan said:
import time
import win32gui
import win32con
import win32api

def turnOffMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2)

def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)

if __name__ == "__main__":
turnOffMonitor()
time.sleep(5)
turnOnMonitor()


What we need here is a matching script that turns off WinXP and leaves
it off too...



.... ouch, <sorry, couldn't help myself> :)



lol
m harris
 
H

harrismh777

harrismh777 said:
def turnOnMonitor():
SC_MONITORPOWER = 0xF170
win32gui.SendMessage(win32con.HWND_BROADCAST,
win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)


I've never tried turning my monitor on/off without using my finger...
gonna have to play with this... wouldn't that be a great script kiddie
tool... just turn off all the windows monitors around the world... no
problem(s) after that...

.... what happens if you try to turn it back on with your finger... ?

.... I have another idea... while its off, try pushing the alt key on
your keyboard... or moving your mouse... (come back on ? )







kind regards,
m harris
 
S

Steven D'Aprano

I've never tried turning my monitor on/off without using my finger...

You've never had your PC turn your monitor off after X minutes of
inactivity?

gonna have to play with this... wouldn't that be a great script kiddie
tool... just turn off all the windows monitors around the world... no
problem(s) after that...

... what happens if you try to turn it back on with your finger... ?

Then you actually turn it off, at the power switch, instead of merely off
in software.

... I have another idea... while its off, try pushing the alt key on
your keyboard... or moving your mouse... (come back on ? )

Presumably you would need to program something to watch for activity and
turn it back on. It would be somewhat embarrassing if you neglected to so
this...
 
H

harrismh777

You've never had your PC turn your monitor off after X minutes of
inactivity?

I know you're being funny, but actually, no-- I don't.


That's a back-in-the-day thing... all of my monitors (and I only have
a couple now because I use VNC to get to the rest of my machines) are
flat panel LED, very low power, cool, and virtually indestructible. I
just leave them on... with beautiful screen savers running... which
aren't screen savers these days either... because nothing really
burns... more like perpetual light-candy eye-pleasers...

Sure, back in the day I configured my system to shutoff the CRT... but
honestly, I haven't had a CRT for almost a decade... you can still
shutdown the flat panel several different ways on the linux platform
based on timing if you want to... in BIOS, in the OS, in gnome, using
the xscreensaver, etc... but, no, I have never written a code routine
to shutoff the monitor (my finger always worked just fine). :)

I wrote a code routine one time just to open the drive bay door,
timer(), and then close the door... from across the network... until
my wife got wise to it, I would open her drive bay door over the
network... it was fun for a while, even after she got wise to it...


.... till the morning I tried it and she had a cup of cocoa sitting on
the desk in front of the drive bay...


.... there have been better days in my house. :)
 
T

Terry Reedy

I've never tried turning my monitor on/off without using my finger...

The computer cannot turn off the monitor. It can only tell the graphics
card to turnoff the signal to the monitor. My monitor then displays 'No
signal detected' in a box and puts itself into a low-power state
awaiting a signal. Even if the monitor does not do that, a black screen
should use less power.

Why the turnon does not work, if indeed it does not (and the monitor is
not failing to respond to its resumption) is not a Python question. 2
and -1 as off and on parameters is a bit strange. The OP might try a
different api reference source or ask on a windows innards list.
 
G

Gregory Ewing

Terry said:
My monitor then displays 'No
signal detected' in a box and puts itself into a low-power state
awaiting a signal. Even if the monitor does not do that, a black screen
should use less power.

I'm not so sure about that. If the monitor is an LCD and isn't
doing anything to reduce its own power usage, then the backlight
is still running and using just as much power, whether the screen
is black or not.
 
H

harrismh777

Gregory said:
I'm not so sure about that. If the monitor is an LCD and isn't
doing anything to reduce its own power usage, then the backlight
is still running and using just as much power, whether the screen
is black or not.

Depends on dpmi. Some monitors turn off the backlight, and some don't.
My monitor(s) that are LCD turn off the backlight... and the downside of
that (very annoying) is that they have to 'warm up' again... making them
dim for the first few seconds of use...

An LED flat panel is a completely different animal, because there is no
backlight (no ccfl). They monitors don't use much power in the first
place, but they use less when they're blank, obviously, not producing light.

kind regards,
m harris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top