atvaxn Posted June 25, 2020 Share Posted June 25, 2020 Hi all, is there a command/way to change the slider for power performance settings in the taskbar? thank you Link to comment Share on other sites More sharing options...
Nine Posted June 25, 2020 Share 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 Decibel 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...
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