Jump to content

How to Know If the Screen(Monitor) is On or Off?


Zohar
 Share

Recommended Posts

Hi

There's something I tried to do in the past, in AutoIt, and have not succeeded yet.

I decided to give it one more try.

Here's what it is:

When I work on my computer, I sometimes have to go for an hour or 2.

When I need to go, I leave my PC On, but I turn off the Screen, manually, by pressing its Power Button.

When I come back, I turn the screen On again(again, manually, via the Power Button of the screen), and continue.

I do not use any Power Settings, nor any ScreenSaver, etc.

This means that when I go, I turn off my screen, but everything keeps working and all is good.

Now to my question:

I would like to be able to check, programatically, If the screen is On or Off.

I use a screen that is connected with a DVI cable, which I know that has a "returning channel" back to the computer,

and in that returning channel, the screen also tells the computer if it's On or Off.

Now I just need a piece of code, that will tell me True/False regarding On/Off of my screen.

In my previous attempt, guinness wrote me this:

Search WMI and Win32_DesktopMonitor, it might provide a solution.

After reading about Win32_DesktopMonitor, I found that:

The Win32_DesktopMonitor class, has a uint16 Availability field,

which among its flags, contains a:

"7 (0x7) Power Off" bit.

Looks good.

To generate the code for querying WMI, I used GEOSoft's Scriptomatic:

http://autoit.mvps.org/files/ai_scriptomatic.zip

I then ran it on my computer,

twice:

First time when the screen is On,

Second time when the screen is Off.

The value of the Availability field when the screen was On, was 3,

and the value when the screen was Off, was also 3..

No change in the field's value, between On and Off..

What I deicded to check now,

Is If this only happens to me(3 returning both when On and when Off), or to everyone.

If it only happens to me, then maybe I can change something in my configuration, to make it work.

(for example change to antoher screen model, change OS, etc..)

But everyone gets 3, both when On and Off,

then it means it's simply not working, and therefore changing my screen/OS will not help :)

Can you guys try it too?

Using scriptomatic, to check the Win32_DesktopMonitor class.

It will really help me.

Thank you

Zohar

Edited by Zohar
Link to comment
Share on other sites

If you fancy writing this in AutoIt you might be in with a chance (on the basis of it being reported as working in linked offsite thread)

http://cboard.cprogramming.com/windows-programming/103275-monitor-state-detection.html#post755545

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi MilesAhead

Thank you for the 3 links,

but unfortuantely they do not talk about the subject,

except one which describes the Win32_DesktopMonitor class in WMI..

(and the person there has the same problem like me: he gets the value 3, both when the screen is On and when it's Off)

Hi JohnOne

This code looks interesting, a function there called print_monitor_info() might be relevant,

but it's C++, and the code is not exactly tidy or readable..

Anyone knows if it runs and achieves the purpose of it?

Link to comment
Share on other sites

From everything that I've read in the dozens of sites I've searched, there's no way to detect if the monitor is powered on or off unless it's possible through the device drivers which no one has been able to find an answer for.

Your best bet would be to post this question on one of the Microsoft support websites and see if it's even possible to detect it through standard Window's calls.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

From everything that I've read in the dozens of sites I've searched, there's no way to detect if the monitor is powered on or off unless it's possible through the device drivers which no one has been able to find an answer for.

I can give you 1 reason why there should be a way.

You know that for many Graphics Cards(including on-board graphics chips),

when you install their Driver+Software,

then clicking their icon in the Taskbar Tray, shows a setting application,

which among many things that relate to the Graphics Card, some of them relate to the screen.

For example,

in many of those applications that come with the Graphics Card, it's possible to change the Brightness and Contrast of the Screen.

Posted Image

(and this works well for most of the new screens.. new = 2005 and above, which is quite enough)

Anyhow,

If those Graphics Cards appilications can do it,

it means there's some general way, to Ask the screen what's its current Brightness and Contrast,

and to also Change it.

So we can do a trick:

1) Ask the screen what's its current Brightness value

2) If the screen answers, then we deduce it's On.

If the screen doesn't answer, then we deduce it's Off.

This should work pretty good..

Anyone knows how to change the brightness or contrast o the screen programatically?

(not by changing how the Graphics Card is displaying it, but by really telling the Screen to change its brightness)

Edited by Zohar
Link to comment
Share on other sites

You are wrong.

By your logic, pixelgetcolor should not work when the monitor is switched off.

Of course it does though.

Every search result (except the link I posted) results in the same conclusion.

people advising to monitor for a global broadcast of 'monitor switching off' type message

(cannot recall off the top of my head what that message is), and it still would not be an

answer to your wish.

I believe there is no simple solution to this.

If it were me that needed such a thing, I'd look into trying the code

in the link I found, and either trying to port it, or creating a dll to use.

Good luck.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

There's no ScreenSaver,

and there's no Power Mode.

As I wrote, in the first post,

My windows is set to no power savings at all.

So there will be no "global broadcast of 'monitor switching off' type message" as JohnOne suggested,

and also no "screen saver" as czardas thought.

Regarding this:

You are wrong.

By your logic, pixelgetcolor should not work when the monitor is switched off.

No - you mix 2 things.

PixelGetColor gets its data from the GraphicsCard memory.

So of course it will work even when the screen is off.

But the Brightness and Contrast,

remember how in old screens they were set using mechanical sliders at the bottom of the screen?

Today they are done via a setting in the screen.

They can also be done via a setting in the graphics card, which changes the image it displays(like gamma settings, etc), but that's something else.

The screen's Brightness and Contrast settings, are what I talk about.

I you want to test what I just said,

you can change a screen's Brightness setting,

then take the screen and connect it to another computer,

then open up the settings application of your Gprahics card,

go to "Screen/Monitor", and you'll see your setting..

Meaning, it's in the screen.

Edited by Zohar
Link to comment
Share on other sites

I you want to test what I just said,

you can change a screen's Brightness setting,

then take the screen and connect it to another computer,

then open up the settings application of your Gprahics card,

go to "Screen/Monitor", and you'll see your setting.

Really? Because if I change the brightness or contrast on my monitor, the video card settings in the software for the card don't reflect the changes I make. Conversely, if I change the brightness and/or contrast on the control panel for my video card, my monitor's brightness value doesn't change.

The 2 are 100% not connected to each other, at least on my Nvidia video card and the 2 monitors I have connected to it. One uses DVI and the other uses a standard SVGA connector in case you think that has any connection to the issue. You're barking up the wrong tree on this one, and you're just making yourself look petulant when you argue for something that's not possible.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@Zohar

I've never heard of anything like that, I can write a script to increase brightness

through my graphics card software (automation) and it will work whether or not the screen

is on.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

If I change the brightness or contrast on my monitor, the video card settings in the software for the card don't reflect the changes I make.

I understand what you mean.

But If you do it in the same way I advised, then you'll see what I mean.

There is a chance tho, that your graphics card software, does not include the Screen's Brightness+Contrast setting, and only its(graphic card) Brightness+Contrast settings. (which in that case, will of course, not be helpful)

My advice is this:

For those of you who have a motherboard with an OnBoard Graphics,

you should have the same Graphics Card Software as I do - which can be seen in the screenshot.

Posted Image

Then, if you go to the "Monitor / TV Settings", and change the Brightness/Contrast there,

then it affects the screen, saved in the screen,

and moving the screen to another computer(that has similar software for the graphics card) you will see the same values!!

Zohar

I've never heard of anything like that, I can write a script to increase brightness

through my graphics card software (automation) and it will work whether or not the screen is on.

The settings that you change are the GraphicsCard ones, and not the Screen ones.

Those Brighness and Contrast that you talk about, are done by your Graphics Card + accompanying software,

and not by the screen.

That's why, it will work for you even when the screen is Off.

Because it is possible to implement Brightness and Contrast settings in Software, many Graphics Cards indeed supply it.

But of course, this will not help us, so this isnot what I talk about.

You need to find the settings that go to the Screen, and done by the screen.

Only then, you can see what I describe..

Edited by Zohar
Link to comment
Share on other sites

Nope, never heard of it, not saying it does not exist, just never seen it.

Control PanelAll Control Panel ItemsDisplayScreen Resolution

On the Screen Resolution gui there is a button for Detect, I imagine it detects the monitor

but I do not know what if any API it might call. I suppose that is something to investigate

as I doubt it could detect if it is switched off.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I tried that code in the link I posted but for me, it reports the monitor power state

as 1 whether it is switched on or off (monitor button only) not tried with physical disconnection.

Is the reason for this detection a secret?

There may be other avenues to explore.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I tried that code in the link I posted but for me, it reports the monitor power state

as 1 whether it is switched on or off (monitor button only) not tried with physical disconnection.

No need to try with Physical disconnection,

since what I'm into checking is just On/Off of the Screen, not disconnecting the wire..

Thank you,

and sad it didn't work..

Is the reason for this detection a secret?

There may be other avenues to explore.

It's not a secret :)

I'll tell you why.

I have my own big script in AutoIt, that I use, that makes using the computer much more automated.

(probably like most people here did for themselves)

In my script, it could be useful to know when the screen is on or off, in order to differentiate the behavior of the script accring to the screen's power state.

Why would we want to differentiate the behavior according to the power state?

For me, when I turn my Screen off, it means I went out,

or went to sleep,

or any kind of "not working on the computer right now".

The screen's power state, is the best way for the computer to know that I am not "on it" now.

(simply because i turn the screen off, myself, via the button, when I leave the computer, and turn the screen on back, when I come back)

Now what kind of script behavior differentiation?:

Let's say I have some alerts in my code for certain events.

If I am not near the computer, then no need to sound any alerts.

So I can make my sound alert function, check if the screen is off, and if yes, then no alert will be sounded.

See?

That way, the screen's Power State, can be another variable, int he list of variables that my script uses, for deciding what and how to do.

Link to comment
Share on other sites

I see.

Only other thing I can suggest (and only if what you say about your software changing your physical monitor brightness is correct)

Is to try to automate that software in a hidden window to increase/decrease and see if there is any identifiable alerts when the monitor is off.

In lieu of a solution for monitor, I'd suggest hitting a hotkey when you switch monitor off.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I see.

Only other thing I can suggest (and only if what you say about your software changing your physical monitor brightness is correct)

Is to try to automate that software in a hidden window to increase/decrease and see if there is any identifiable alerts when the monitor is off.

Instead of using a Hidden window, we might be able to do a trick:

The same way WireShark can sniff Ethernet,

there should be a way to sniff data Sent and Received from IO Ports.

The screen, should have some IO Port.

Then If we sniff it, we cn find a way what to send, and what to receive (or not receive), for knowing when it's On or Off..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...