atvaxn 0 Posted June 25, 2020 Hi all, is there a command/way to change the slider for power performance settings in the taskbar? thank you Share this post Link to post Share on other sites
Nine 932 Posted June 25, 2020 To start you up with UIAutomation : expandcollapse popup#NoTrayIcon #include "Includes\CUIAutomation2.au3" #include <Constants.au3> Opt ("MustDeclareVars", 1) _Systray_SelectOption() Func _Systray_SelectOption() Local $hWnd = WinGetHandle('[Class:Shell_TrayWnd]') If Not $hWnd Then Return SetError(1) Local $hCtrl = ControlGetHandle($hWnd, '', "ToolbarWindow323") If Not $hCtrl Then Return SetError(2) ; Create UI Automation object 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 element by handle Local $pElement, $oElement $oUIAutomation.ElementFromHandle($hCtrl, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF) ConsoleWrite("$oElement OK" & @CRLF) ; Get condition (ControlType = Button) Local $pCondition, $oCondition $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF) ConsoleWrite("$oCondition OK" & @CRLF) ; Find all buttons 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 buttons Local $aElements[$iElements] For $i = 0 To $iElements - 1 $oElementArray.GetElement($i, $pElement) $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Next ; Get name and position for each button Local $vValue, $bFound = False Local $tPoint = DllStructCreate("long X;long Y"), $bBool For $i = 0 To UBound($aElements) - 1 $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $vValue) ConsoleWrite("Name:" & $vValue & @CRLF) $aElements[$i].GetClickablePoint ($tPoint, $bBool) If StringRegExp ($vValue, "\(\d{1,3}.%\)") Then MouseClick ("left", $tPoint.X, $tPoint.Y, 1, 1) $bFound = True ExitLoop EndIf Next Sleep (1500) $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Windows.UI.Core.CoreWindow", $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) Local $pPower, $oPower $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition, $pPower ) $oPower = ObjCreateInterface( $pPower, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oPower ) Then Return ConsoleWrite( "$oPower ERR" & @CRLF ) ConsoleWrite( "$oPower OK" & @CRLF ) $oUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "Slider", $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF) ConsoleWrite("$oCondition OK" & @CRLF) $oPower.FindFirst($TreeScope_Children, $oCondition, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF) ConsoleWrite("$oElement OK" & @CRLF) Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom") $oElement.CurrentBoundingRectangle($tRect) ConsoleWrite(" L:" & $tRect.Left & " T:" & $tRect.Top & " R:" & $tRect.Right & " B:" & $tRect.Bottom & @CRLF) Local $x = $tRect.Left + Int(($tRect.Right-$tRect.Left)*.5) ; calculate center of slider Local $y = $tRect.Top + Int(($tRect.Bottom-$tRect.Top)*.75) MouseClick ("left", $x, $y, 1, 1) EndFunc Not much of a signature, but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Tool to search content in au3 files Date Range Picker Sudoku Game 2020 Overlapped Named Pipe IPC x64 Bitwise Operations Fast and simple WCD IPC GIF Animation (cached) Share this post Link to post Share on other sites