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?
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
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
Wonder what the equivalent of this is in Linux... ?
> harrismh777 wrote:
>>
>> 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...
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...
--
Steven
Probably xset dpms force {on,off,...}
> 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. :)
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.
--
Terry Jan Reedy
... this was my point ;-)
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.
--
Greg
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
> 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):
>
> def turnOnMonitor():
> SC_MONITORPOWER = 0xF170
> win32gui.SendMessage(win32con.HWND_BROADCAST,
> win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1)
>
> For some reason, the script doesn't turn the monitor back on. What am
> I doing wrong here or are there any other alternative?
Your script worked fine for me, 2.6 and XP also. Perhaps your monitor
device driver is buggy or does not implement the required functionality.
Mine is from Philips.
--
Gabriel Genellina
This code does not return control to you, so programm still locked. In my opinion it due broadcasting message. But I do not know how to send message to monitor directly.