Jump to content

how to detect if secondary monitor is on?


Recommended Posts

thanks those were good starting points that lead me to 

 

 

but the problem is that all those posts including this latest one does not detect if the secondary monitor is on. if i turn my secondary monitor then off, it still thinks its on and gives me wrong dimensions.

Link to comment
Share on other sites

woow  i thinked (but not sure) if  you want understund if monitor is switched on or off you must use a webcam point in fornt of 2 monitor  and  when second monitor is on do choice

or try to look here

 

Edited by faustf
Link to comment
Share on other sites

On 5/21/2020 at 1:22 AM, dwaynek said:

how do i detect if a secondary monitor is on?

You can not. Just as you can not know, if the speakers are turned on or not.
That is a hardware problem without software solution :(

Maybe one day monitor makers will grant us the possibility.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

nirsoft looked interesting but unfortunately did not produce the outcome i want.

however i did notice that if i go into the Display settings under Windows Settings, system, display and click on the Detect button, it will reset and detect what monitors are on or off so that the DesktopDimensions function works accurately again.

so now my issue is how can i trigger display detection from autoit or from the command line?

Edited by dwaynek
Link to comment
Share on other sites

Link to comment
Share on other sites

Alright then, UIAutomation is another way to achieve it under win 10 

#include <Constants.au3>
#include <Array.au3>
#include "Includes\CUIAutomation2.au3"

Opt("MustDeclareVars", 1)
Run("control.exe desk.cpl,Settings,@Settings")

GetMonitor()

Func GetMonitor()
  Local $hWnd = WinWait("[CLASS:ApplicationFrameWindow]")
  ConsoleWrite($hWnd & @CRLF)

  Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
  If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF)
  ConsoleWrite("$oUIAutomation OK" & @CRLF)

  ; Get Desktop element
  Local $pDesktop, $oDesktop
  $oUIAutomation.GetRootElement($pDesktop)
  $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF)
  ConsoleWrite("$oDesktop OK" & @CRLF)

  ;Get application window
  Local $pCondition, $pElement, $oElement
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "ApplicationFrameWindow", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  Sleep (2000)

  $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Frame Window OK" & @CRLF)

  ; Get core window
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Windows.UI.Core.CoreWindow", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  $oElement.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Core window OK" & @CRLF)

  ; Get scroll Viewer
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "ScrollViewer", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  $oElement.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Scroll Viewer OK" & @CRLF)

  ; Get condition (ControlType = $UIA_GroupControlTypeId)
  Local $oCondition
  $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_GroupControlTypeId, $pCondition)
  $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition)
  If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF)
  ConsoleWrite("$oCondition OK" & @CRLF)

  ; Find all groups
  Local $pElementArray, $oElementArray, $iElements
  $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray)
  $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
  $oElementArray.Length($iElements)
  If Not IsObj($oElementArray) Then Return ConsoleWrite("$oElementArray ERR" & @CRLF)
  ConsoleWrite("$oElementArray OK" & @CRLF)

  ; Get array of Groups
  Local $aElements[$iElements]
  For $i = 0 To $iElements - 1
    $oElementArray.GetElement($i, $pElement)
    $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  Next

  ; Get name for each group
  Local $vValue, $oGroup
  For $i = 0 To UBound($aElements) - 1
    $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $vValue)
    ConsoleWrite("Name:" & $vValue & @CRLF)
    If $vValue = "Plusieurs écrans" Then
      $oGroup = $aElements[$i]
      ExitLoop
    EndIf
  Next
  If Not IsObj($oGroup) Then Return ConsoleWrite("$oGroup ERR" & @CRLF)
  ConsoleWrite("$oGroup OK" & @CRLF)

  ; Get detect button
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Button", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  $oElement.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Button OK" & @CRLF)

  $oElement.GetCurrentPropertyValue($UIA_IsOffscreenPropertyId, $vValue)

  If $vValue Then
    Send("{PGDN}")
    Sleep(1500)
  EndIf

  Local $tPoint = DllStructCreate("long X;long Y"), $bBool
  $oElement.GetClickablePoint($tPoint, $bBool)
  MouseClick("left", $tPoint.X, $tPoint.Y, 1, 1)

EndFunc   ;==>GetMonitor

:

 

Link to comment
Share on other sites

On 5/25/2020 at 1:36 PM, Nine said:

Alright then, UIAutomation is another way to achieve it under win 10 

#include <Constants.au3>
#include <Array.au3>
#include "Includes\CUIAutomation2.au3"

Opt("MustDeclareVars", 1)
Run("control.exe desk.cpl,Settings,@Settings")

GetMonitor()

Func GetMonitor()
  Local $hWnd = WinWait("[CLASS:ApplicationFrameWindow]")
  ConsoleWrite($hWnd & @CRLF)

  Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
  If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF)
  ConsoleWrite("$oUIAutomation OK" & @CRLF)

  ; Get Desktop element
  Local $pDesktop, $oDesktop
  $oUIAutomation.GetRootElement($pDesktop)
  $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF)
  ConsoleWrite("$oDesktop OK" & @CRLF)

  ;Get application window
  Local $pCondition, $pElement, $oElement
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "ApplicationFrameWindow", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  Sleep (2000)

  $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Frame Window OK" & @CRLF)

  ; Get core window
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Windows.UI.Core.CoreWindow", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  $oElement.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Core window OK" & @CRLF)

  ; Get scroll Viewer
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "ScrollViewer", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  $oElement.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Scroll Viewer OK" & @CRLF)

  ; Get condition (ControlType = $UIA_GroupControlTypeId)
  Local $oCondition
  $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_GroupControlTypeId, $pCondition)
  $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition)
  If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF)
  ConsoleWrite("$oCondition OK" & @CRLF)

  ; Find all groups
  Local $pElementArray, $oElementArray, $iElements
  $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray)
  $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
  $oElementArray.Length($iElements)
  If Not IsObj($oElementArray) Then Return ConsoleWrite("$oElementArray ERR" & @CRLF)
  ConsoleWrite("$oElementArray OK" & @CRLF)

  ; Get array of Groups
  Local $aElements[$iElements]
  For $i = 0 To $iElements - 1
    $oElementArray.GetElement($i, $pElement)
    $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  Next

  ; Get name for each group
  Local $vValue, $oGroup
  For $i = 0 To UBound($aElements) - 1
    $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $vValue)
    ConsoleWrite("Name:" & $vValue & @CRLF)
    If $vValue = "Plusieurs écrans" Then
      $oGroup = $aElements[$i]
      ExitLoop
    EndIf
  Next
  If Not IsObj($oGroup) Then Return ConsoleWrite("$oGroup ERR" & @CRLF)
  ConsoleWrite("$oGroup OK" & @CRLF)

  ; Get detect button
  $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Button", $pCondition)
  If Not $pCondition Then Return ConsoleWrite("$pCondition ERR" & @CRLF)
  ConsoleWrite("$pCondition OK" & @CRLF)

  $oElement.FindFirst($TreeScope_Descendants, $pCondition, $pElement)
  $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement)
  If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF)
  ConsoleWrite("Button OK" & @CRLF)

  $oElement.GetCurrentPropertyValue($UIA_IsOffscreenPropertyId, $vValue)

  If $vValue Then
    Send("{PGDN}")
    Sleep(1500)
  EndIf

  Local $tPoint = DllStructCreate("long X;long Y"), $bBool
  $oElement.GetClickablePoint($tPoint, $bBool)
  MouseClick("left", $tPoint.X, $tPoint.Y, 1, 1)

EndFunc   ;==>GetMonitor

 

pardon the ignorance, where do i find CUIAutomation2.au3?

Edited by dwaynek
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...