dwaynek Posted May 21, 2020 Share Posted May 21, 2020 how do i detect if a secondary monitor is on? i'd like to move a window to the secondary monitor only if its on and to let it remain on the primary monitor if its off. Link to comment Share on other sites More sharing options...
faustf Posted May 21, 2020 Share Posted May 21, 2020 probably this topic can help you Link to comment Share on other sites More sharing options...
dwaynek Posted May 23, 2020 Author Share Posted May 23, 2020 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 More sharing options...
faustf Posted May 23, 2020 Share Posted May 23, 2020 (edited) 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 May 23, 2020 by faustf Link to comment Share on other sites More sharing options...
argumentum Posted May 23, 2020 Share Posted May 23, 2020 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. Bilgus 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Bilgus Posted May 23, 2020 Share Posted May 23, 2020 Some Tvs / monitors have CEC commands that I suspect you could use but I've yet to see it ever work Link to comment Share on other sites More sharing options...
Bilgus Posted May 23, 2020 Share Posted May 23, 2020 Maybe this from NirSoft has command line interface too https://www.nirsoft.net/utils/control_my_monitor.html unfortunately it doesn't work for me but YMMV Link to comment Share on other sites More sharing options...
dwaynek Posted May 25, 2020 Author Share Posted May 25, 2020 (edited) 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 May 25, 2020 by dwaynek Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2020 Share Posted May 25, 2020 Try this (tested on french win7) : Run("control.exe desk.cpl,Settings,@Settings") Local $hWnd = WinWait("[CLASS:CabinetWClass]","Résolution") Local $hCtrl = ControlGetHandle ($hWnd, "", "Button1") ConsoleWrite ($hWnd & "/" & $hCtrl & @CRLF) ControlClick ($hWnd, "", $hCtrl) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Exit Posted May 25, 2020 Share Posted May 25, 2020 Unfortunately, this no longer works under windows 10 😟 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2020 Share Posted May 25, 2020 Alright then, UIAutomation is another way to achieve it under win 10 expandcollapse popup#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 : Exit 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Exit Posted May 25, 2020 Share Posted May 25, 2020 Very nice solution 🙂 When you insert $oGroup = $aElements[2] after line 89 ( after next) then it works also for non french users. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Nine Posted May 25, 2020 Share Posted May 25, 2020 @Exit Yep, that would work too, until MS changes the page to add another feature... Exit 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
dwaynek Posted May 29, 2020 Author Share Posted May 29, 2020 (edited) On 5/25/2020 at 1:36 PM, Nine said: Alright then, UIAutomation is another way to achieve it under win 10 expandcollapse popup#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 May 29, 2020 by dwaynek Link to comment Share on other sites More sharing options...
Exit Posted May 30, 2020 Share Posted May 30, 2020 9 hours ago, dwaynek said: where do i find CUIAutomation2.au3? https://www.autoitscript.com/forum/applications/core/interface/file/attachment.php?id=61194 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now