Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Reading information from Power Setting GUIDs


  • Please log in to reply
13 replies to this topic
kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

Hi

 
 
I am writing a script to run which does the following:
Detect if TV is off, If off then run external program (an IR blaster commandline that turns on TV)
 
I have been able to access stuff from Win32_DesktopMonitor Class

http://msdn.microsof...2(v=vs.85).aspx

; Initialize Monitor handle
hMon := DllCall("MonitorFromPoint"
, "int64", 0 ; point on monitor
, "uint", 1) ; flag to return primary monitor on failure
 
; Find number of Physical Monitors
DllCall("dxva2\GetNumberOfPhysicalMonitorsFromHMONITOR"
, "int", hMon
, "uint*", nMon)
 
; Get Physical Monitor from handle
VarSetCapacity(Physical_Monitor, (A_PtrSize ? A_PtrSize : 4) + 128, 0)
 
DllCall("dxva2\GetPhysicalMonitorsFromHMONITOR"
, "int", hMon   ; monitor handle
, "uint", nMon   ; monitor array size
, "int", &Physical_Monitor)   ; point to array with monitor
 
hPhysMon := NumGet(Physical_Monitor)
 
 
DllCall("dxva2\GetMonitorBrightness"
, "int", hPhysMon
, "uint*", minBright
, "uint*", curBright
, "uint*", maxBright)
 
 
DllCall("dxva2\GetMonitorCapabilities"
, "int", hPhysMon
, "uint*", pdwMonitorCap
, "uint*", pdwMonitorSup)
         
MsgBox % "Monitor description: " . StrGet(&Physical_Monitor+(A_PtrSize ? A_PtrSize : 4), "utf-16")
. "`nMinimum brightness: " . minBright
. "`nMaximum brightness: " . maxBright
. "`nCurrent brightness: " . curBright
        . "`nPdwMonitorCapabilities: " . pdwMonitorCap
        . "`nPdwMonitorSupport: " . pdwMonitorSup
 
and also everything inside
 
class Win32_DesktopMonitor : CIM_DesktopMonitor
{
uint16   Availability;
uint32   Bandwidth;
string   Caption;
uint32   ConfigManagerErrorCode;
boolean  ConfigManagerUserConfig;
string   CreationClassName;
string   Description;
string   DeviceID;
uint16   DisplayType;
boolean  ErrorCleared;
string   ErrorDescription;
datetime InstallDate;
boolean  IsLocked;
uint32   LastErrorCode;
string   MonitorManufacturer;
string   MonitorType;
string   Name;
uint32   PixelsPerXLogicalInch;
uint32   PixelsPerYLogicalInch;
string   PNPDeviceID;
uint16   PowerManagementCapabilities[];
boolean  PowerManagementSupported;
uint32   ScreenHeight;
uint32   ScreenWidth;
string   Status;
uint16   StatusInfo;
string   SystemCreationClassName;
string   SystemName;
};
 
However none of the above changes when i toggle tv power.
 
I have been told that I should try
 
WM_DEVICECHANGE/GUID_MONITOR_POWER_ON 
 
But I can't figure out how to access this information
 
Can anyone help me please?
 
Thanks
Kiwi


strobo
  • Members
  • 359 posts
  • Last active: Mar 10 2015 08:13 PM
  • Joined: 19 Jun 2012

Hi kiwi,
this one detects device changes (and I will make use of it, thanks)

WM_DEVICECHANGE := 0x0219
onmessage(WM_DEVICECHANGE, "callback_function")
callback_function(wparam, lparam, msg, hwnd){
    msgbox,% wparam "`n" lparam "`n" msg "`n" hwnd
}
esc::exitapp
BUT as it seems, display Power ON/OFF are not covered by this:(
Regards,
Babba

kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

Thanks Babba, you are right that doesn't catch display power changes sad.png

 

I don't necessarily have to catch it with a device change.  It is enough just to be able to check.  My script I am writing needs to do the following when run.

 

If (TV is on) { do nothing } else { run external commandline to IR blast the TV }

 

Do you know how to read anything from:

http://msdn.microsof...0(v=vs.85).aspx

 

It seems you have to define the GUID first

eg. for detecting opening + closing lid on a laptop

DEFINE_GUID( GUID_LIDSWITCH_STATE_CHANGE,  0xBA3E0F4D, 0xB817, 0x4094, 0xA2, 0xD1, 0xD5, 0x63, 0x79, 0xE6, 0xA0, 0xF3 );


Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

By TV, I assume you mean the monitor.

Spoiler

Based on this, you can develop apps based on other GUIDs which are available in WinNt.h from the Windows SDK.

If you use more than one GUID, this can be used to distinguish the notifications.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

Thank you.

 

I change tooltip to msgbox, 64, ON/OFF so it made sound effects.

 

Unfortunately,

when the script is run it gives monitor ON regardless of whether my monitor is on or off

It also fails to doesn't detect toggleing my monitor on or off.

 

Havn't tried it with my TV yet.

 

The reason I mentioned TV was because the script is for my HTPC happy.png



Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

Thank you.
 
I change tooltip to msgbox, 64, ON/OFF so it made sound effects.
 
Unfortunately,
when the script is run it gives monitor ON regardless of whether my monitor is on or off
It also fails to doesn't detect toggleing my monitor on or off.
 
Havn't tried it with my TV yet.
 
The reason I mentioned TV was because the script is for my HTPC happy.png

I have tested on my laptop's LCD, and I do not own a desktop for testing. Maybe it works only on laptop like devices ?


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

maybe, I'll let you know how it goes on my TV.

 

If it doesn't work I have heard of people complaining that HDMI audio stops working when they turn off their TV (PC -> HDMI -> Receiver -> HDMI -> TV) so maybe there is something in that, that I can use ;)



kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

doesn't work.  I used team viewer to remote into my HTPC (the TV is currently off) and the script thinks the monitor is on :( :(



Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

What is your OS ? It's designed for Windows 8.

EDIT : I have edited the original script file above so that it checks and automatically compensates for OS. Retry.

I have modified it so that it plays sound without pausing the thread. Pausing the thread during OnMessage functions may cause problems.

It now uses GUID_MONITOR_POWER_ON which you have quoted in the original post.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

Tried it on my desktop it doesn't work. same result as last time.

 

Monitor Off: Run script, makes noise once

Monitor On: Run script, makes noise once

 

Monitor On: Run script makes noise once, Turn Monitor Off + On, no further noise.

 

:(



Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

I see nothing wrong with Rijul's script. The only potential problem I can see is how you're turning on/off the monitor. There's turning it off with the power button, and there's Windows simply not sending it anything to display. Try adding this hotkey to Rijul's script (at the very bottom is easiest). The hotkey is triggered by Alt+m. It will turn off your monitor in a similar fashion to how Windows turns it off after a period of inactivity. To restore power, just shake the mouse or press a key.

!m::
  ;Specifically wait until the hotkey is released before powering down the monitor
  ;This prevents triggering the monitor on as soon as the keys are released
  KeyWait, Alt, u
  KeyWait, m, u
  SendMessage, 0x112, 0xF170, 2,, Program Manager
return

Join us at the new forum - http://www.ahkscript.org/

 


kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

Thanks, yes i know this.  I want to detect if the display is powered up or not.  Not whether windows has turned off the display :)

 

I am writing a script to run which does the following:
Detect if TV is off, If off then run external program (an IR blaster commandline that turns on TV)


Linear Spoon
  • Members
  • 842 posts
  • Last active: Sep 29 2015 03:56 AM
  • Joined: 29 Oct 2011

I'm sorry then, you probably won't be able to detect that.


Join us at the new forum - http://www.ahkscript.org/

 


kiwijunglist
  • Members
  • 61 posts
  • Last active: Aug 14 2013 05:56 AM
  • Joined: 26 May 2009

Should be possible somehow, because if an hdmi display is off it won't respond to EDID handshake requests.