Jump to content

Using SetValue() on Slider Control


rmckay
 Share

Recommended Posts

I'm trying to set the slider in a window using RangeValuePattern.SetValue().  The window is used to set the start point for replaying market data in the app NinjaTrader 8. When using the Action window in Inspect.exe I can set a value and the slider responds.  When I run a script that selects the slider and uses .SetValue() with the same value the slider does not move.  I've tried giving the focus to the slider with no change in results.  

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code
#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code

#include "C:\Users\Rod\Documents\AutoIt\Include\UIA_Constants.au3" ; Can be copied from UIASpy Includes folder

;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder
;#include "UIA_Variant.au3" ; Can be copied from UIASpy Includes folder

Opt("MustDeclareVars", 1)

Example()

Func Example()



    ; Create UI Automation object
    Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation8, $sIID_IUIAutomation5, $dtag_IUIAutomation5)
    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_IUIAutomationElement8, $dtag_IUIAutomationElement8)
    If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF)
    ConsoleWrite("$oDesktop OK" & @CRLF)

    ; --- Find window/control ---

    ConsoleWrite("--- Find window/control ---" & @CRLF)

    Local $pCondition0
    $oUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Playback", $pCondition0)
    If Not $pCondition0 Then Return ConsoleWrite("$pCondition0 ERR" & @CRLF)
    ConsoleWrite("$pCondition0 OK" & @CRLF)

    Local $pWindow1, $oWindow1
    $oDesktop.FindFirst($TreeScope_Descendants, $pCondition0, $pWindow1)
    $oWindow1 = ObjCreateInterface($pWindow1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8)
    If Not IsObj($oWindow1) Then Return ConsoleWrite("$oWindow1 ERR" & @CRLF)
    ConsoleWrite("$oWindow1 OK" & @CRLF)

    ; --- Find window/control ---

    ConsoleWrite("--- Find window/control ---" & @CRLF)

    Local $pCondition1
    $oUIAutomation.CreatePropertyCondition($UIA_AutomationIdPropertyId, "slider", $pCondition1)
    If Not $pCondition1 Then Return ConsoleWrite("$pCondition1 ERR" & @CRLF)
    ConsoleWrite("$pCondition1 OK" & @CRLF)

    Local $pSlider1, $oSlider1
    $oWindow1.FindFirst($TreeScope_Descendants, $pCondition1, $pSlider1)
    $oSlider1 = ObjCreateInterface($pSlider1, $sIID_IUIAutomationElement8, $dtag_IUIAutomationElement8)
    If Not IsObj($oSlider1) Then Return ConsoleWrite("$oSlider1 ERR" & @CRLF)
    ConsoleWrite("$oSlider1 OK" & @CRLF)
    ; --- RangeValue Pattern (action) Object ---

    ConsoleWrite("--- RangeValue Pattern (action) Object ---" & @CRLF)

    Local $pRangeValuePattern1, $oRangeValuePattern1
    $oSlider1.GetCurrentPattern($UIA_RangeValuePatternId, $pRangeValuePattern1)
    $oRangeValuePattern1 = ObjCreateInterface($pRangeValuePattern1, $sIID_IUIAutomationRangeValuePattern, $dtag_IUIAutomationRangeValuePattern)
    If Not IsObj($oRangeValuePattern1) Then Return ConsoleWrite("$oRangeValuePattern1 ERR" & @CRLF)
    ConsoleWrite("$oRangeValuePattern1 OK" & @CRLF)

    ; --- RangeValue Pattern (action) Methods ---

    ConsoleWrite("--- RangeValue Pattern (action) Methods ---" & @CRLF)
    Local $iSetValue = 50000
    $oRangeValuePattern1.SetValue($iSetValue)
    ConsoleWrite("$oRangeValuePattern1.SetValue()" & @CRLF)
EndFunc   ;==>Example

Console Output

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Rod\Documents\AutoIt\NT8 PlayBack\NT8 PlayBack01.au3" /UserParams    
+>10:39:16 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:2
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Rod\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  params:-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\Rod\Documents\AutoIt\NT8 PlayBack\NT8 PlayBack01.au3
+>10:39:16 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\Rod\Documents\AutoIt\NT8 PlayBack\NT8 PlayBack01.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
$oUIAutomation OK
$oDesktop OK
--- Find window/control ---
$pCondition0 OK
$oWindow1 OK
--- Find window/control ---
$pCondition1 OK
$oSlider1 OK
--- RangeValue Pattern (action) Object ---
$oRangeValuePattern1 OK
--- RangeValue Pattern (action) Methods ---
$oRangeValuePattern1.SetValue()
+>10:39:16 AutoIt3.exe ended.rc:0
+>10:39:16 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.087

I'm a noob with autoit and tried to attach screenshots to this post.  I have shots from UIASpy and Inspect.exe.  When I try to attach them I get an "Upload Failed" message.  They show results from the respective programs.  As an alternative I included the apps results with the slider selected.

Inspect.exe:

How found:    Selected from tree...
Name:    ""
ControlType:    UIA_SliderControlTypeId (0xC35F)
LocalizedControlType:    "slider"
BoundingRectangle:    {l:1579 t:531 r:1801 b:549}
IsEnabled:    true
IsOffscreen:    false
IsKeyboardFocusable:    true
HasKeyboardFocus:    false
AcceleratorKey:    ""
AccessKey:    ""
ProcessId:    9928
RuntimeId:    [7.26C8.279F814]
AutomationId:    "slider"
FrameworkId:    "WPF"
ClassName:    "Slider"
IsControlElement:    true
IsContentElement:    true
ProviderDescription:    "[pid:9928,providerId:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]"
IsPassword:    false
ItemStatus:    ""
ItemType:    ""
IsRequiredForForm:    false
HelpText:    ""
ClickablePoint:    {x:-2147483648 y:-2147483648}
Orientation:    0
LegacyIAccessible.ChildId:    0
LegacyIAccessible.DefaultAction:    ""
LegacyIAccessible.Description:    ""
LegacyIAccessible.Help:    ""
LegacyIAccessible.KeyboardShortcut:    ""
LegacyIAccessible.Name:    ""
LegacyIAccessible.Role:    slider (0x33)
LegacyIAccessible.State:    focusable (0x100000)
LegacyIAccessible.Value:    "0"
RangeValue.IsReadOnly:    false
RangeValue.LargeChange:    1.000000
RangeValue.Maximum:    691200.000000
RangeValue.Minimum:    0.000000
RangeValue.SmallChange:    0.100000
RangeValue.Value:    0.000000
IsAnnotationPatternAvailable:    false
IsDragPatternAvailable:    false
IsDockPatternAvailable:    false
IsDropTargetPatternAvailable:    false
IsExpandCollapsePatternAvailable:    false
IsGridItemPatternAvailable:    false
IsGridPatternAvailable:    false
IsInvokePatternAvailable:    false
IsItemContainerPatternAvailable:    false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable:    false
IsObjectModelPatternAvailable:    false
IsRangeValuePatternAvailable:    true
IsScrollItemPatternAvailable:    false
IsScrollPatternAvailable:    false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsSpreadsheetItemPatternAvailable:    false
IsSpreadsheetPatternAvailable:    false
IsStylesPatternAvailable:    false
IsSynchronizedInputPatternAvailable:    true
IsTableItemPatternAvailable:    false
IsTablePatternAvailable:    false
IsTextChildPatternAvailable:    false
IsTextEditPatternAvailable:    false
IsTextPatternAvailable:    false
IsTextPattern2Available:    false
IsTogglePatternAvailable:    false
IsTransformPatternAvailable:    false
IsTransform2PatternAvailable:    false
IsValuePatternAvailable:    false
IsVirtualizedItemPatternAvailable:    false
IsWindowPatternAvailable:    false
IsCustomNavigationPatternAvailable:    false
IsSelectionPattern2Available:    false
FirstChild:    "" thumb
LastChild:    "" thumb
Next:    "M0,3C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 3,3 4,3 4,3 4,3 4,4 4,4 4,4 7,4 7,4 7,4 7,3 7,3 7,3 6,3 6,3 6,3 6,2 6,2 6,2 5,2 5,2 5,
Previous:    "" button
Other Props:    Object has no additional properties
Children:    "" thumb
Ancestors:    "Playback" window
    "Desktop 1" pane
    [ No Parent ]
 

UIASpy:

Treeview Element                                    Slider: Slider
                                                    
Element Properties (identification)                 
$UIA_AutomationIdPropertyId                         slider
$UIA_ClassNamePropertyId                            Slider
$UIA_ControlTypePropertyId                          $UIA_SliderControlTypeId
                                                    
Element Properties (session unique)                 
$UIA_ProcessIdPropertyId                            9928
$UIA_RuntimeIdPropertyId                            7,9928,41547796
                                                    
Element Properties (information)                    
$UIA_BoundingRectanglePropertyId                    l=1579,t=531,w=222,h=18
$UIA_ClickablePointPropertyId                       -2147483648,-2147483648
$UIA_FrameworkIdPropertyId                          WPF
$UIA_HeadingLevelPropertyId                         80050
$UIA_LocalizedControlTypePropertyId                 slider
$UIA_OptimizeForVisualContentPropertyId             False
$UIA_ProviderDescriptionPropertyId                  [pid:9928,providerId:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]
                                                    
Element Properties (has/is info)                    
$UIA_HasKeyboardFocusPropertyId                     False
$UIA_IsContentElementPropertyId                     True
$UIA_IsControlElementPropertyId                     True
$UIA_IsDataValidForFormPropertyId                   False
$UIA_IsDialogPropertyId                             False
$UIA_IsEnabledPropertyId                            True
$UIA_IsKeyboardFocusablePropertyId                  True
$UIA_IsOffscreenPropertyId                          False
$UIA_IsPasswordPropertyId                           False
$UIA_IsPeripheralPropertyId                         False
$UIA_IsRequiredForFormPropertyId                    False
                                                    
Control Patterns (element actions)                  
$UIA_IsLegacyIAccessiblePatternAvailablePropertyId  True (LegacyIAccessiblePattern)
$UIA_IsRangeValuePatternAvailablePropertyId         True (RangeValuePattern)
$UIA_IsSynchronizedInputPatternAvailablePropertyId  True (SynchronizedInputPattern)
                                                    
Control Pattern Properties                          
$UIA_LegacyIAccessibleChildIdPropertyId             0
$UIA_LegacyIAccessibleDefaultActionPropertyId       
$UIA_LegacyIAccessibleDescriptionPropertyId         
$UIA_LegacyIAccessibleHelpPropertyId                
$UIA_LegacyIAccessibleKeyboardShortcutPropertyId    
$UIA_LegacyIAccessibleNamePropertyId                
$UIA_LegacyIAccessibleRolePropertyId                51 = $ROLE_SYSTEM_SLIDER
$UIA_LegacyIAccessibleStatePropertyId               1048576 = $STATE_SYSTEM_FOCUSABLE
$UIA_LegacyIAccessibleValuePropertyId               0
$UIA_RangeValueIsReadOnlyPropertyId                 False
$UIA_RangeValueLargeChangePropertyId                1
$UIA_RangeValueMaximumPropertyId                    691199.9999999
$UIA_RangeValueMinimumPropertyId                    0
$UIA_RangeValueSmallChangePropertyId                0.1
$UIA_RangeValueValuePropertyId                      2.47032822920623e-319
                                                    
Control Pattern Methods                             
LegacyIAccessible Pattern Methods                   
                                                    DoDefaultAction()
                                                    Select(long)
                                                    SetValue(wstr)
                                                    GetIAccessible(idispatch*)
                                                    CurrentChildId(int*)
                                                    CurrentDefaultAction(bstr*)
                                                    CurrentDescription(bstr*)
                                                    CurrentHelp(bstr*)
                                                    CurrentKeyboardShortcut(bstr*)
                                                    CurrentName(bstr*)
                                                    CurrentRole(uint*)
                                                    CurrentState(uint*)
                                                    CurrentValue(bstr*)
                                                    GetCurrentSelection(ptr*)
RangeValue Pattern Methods                          
                                                    SetValue(ushort)
                                                    CurrentIsReadOnly(long*)
                                                    CurrentMaximum(ushort*)
                                                    CurrentMinimum(ushort*)
                                                    CurrentLargeChange(ushort*)
                                                    CurrentSmallChange(ushort*)
                                                    CurrentValue(ushort*)
SynchronizedInput Pattern Methods                   
                                                    StartListening(long)
                                                    Cancel()
                                                    
Parents from Desktop                                Pane: Desktop 1
                                                    Window: Playback
                                                    
Parent to child index                               
 

In addition to this problem, I am unable to press the start button with an autoit script or by using inspect.exe=>Action=>Toggle() or inspect.exe=>Action=>DoDefaultAction().  I'll post that after solving the current problem.


 

Link to comment
Share on other sites

In the $dtag_IUIAutomationRangeValuePattern definition in UIA_Constants.au3, please correct all ushort

Global Const $sIID_IUIAutomationRangeValuePattern = "{59213F4F-7346-49E5-B120-80555987A148}"
Global Const $dtag_IUIAutomationRangeValuePattern = _
  "SetValue hresult(ushort);" & _
  "CurrentValue hresult(ushort*);" & _
  "CurrentIsReadOnly hresult(long*);" & _
  "CurrentMaximum hresult(ushort*);" & _
  "CurrentMinimum hresult(ushort*);" & _
  "CurrentLargeChange hresult(ushort*);" & _
  "CurrentSmallChange hresult(ushort*);" & _
  "CachedValue hresult(ushort*);" & _
  "CachedIsReadOnly hresult(long*);" & _
  "CachedMaximum hresult(ushort*);" & _
  "CachedMinimum hresult(ushort*);" & _
  "CachedLargeChange hresult(ushort*);" & _
  "CachedSmallChange hresult(ushort*);"

to double this way:

Global Const $sIID_IUIAutomationRangeValuePattern = "{59213F4F-7346-49E5-B120-80555987A148}"
Global Const $dtag_IUIAutomationRangeValuePattern = _
  "SetValue hresult(double);" & _
  "CurrentValue hresult(double*);" & _
  "CurrentIsReadOnly hresult(long*);" & _
  "CurrentMaximum hresult(double*);" & _
  "CurrentMinimum hresult(double*);" & _
  "CurrentLargeChange hresult(double*);" & _
  "CurrentSmallChange hresult(double*);" & _
  "CachedValue hresult(double*);" & _
  "CachedIsReadOnly hresult(long*);" & _
  "CachedMaximum hresult(double*);" & _
  "CachedMinimum hresult(double*);" & _
  "CachedLargeChange hresult(double*);" & _
  "CachedSmallChange hresult(double*);"

Then run your code again.

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

×
×
  • Create New...