Jump to content

controlclick on systemtray and dropdownmenu


 Share

Recommended Posts

hey guys i want to  simulate a click on my vpn thats in  my systemtray and then turn it on and off .. the on offbuttons are inthe menu and i cant analyze it with the window info tool ...

heres what it gives me about the tray :

>>>> Window <<<<
Title:  
Class:  Shell_TrayWnd
Position:   0, 824
Size:   1536, 40
Style:  0x96000000
ExStyle:    0x00000088
Handle: 0x0001010A

>>>> Control <<<<
Class:  ToolbarWindow32
Instance:   3
ClassnameNN:    ToolbarWindow323
Name:   
Advanced (Class):   [CLASS:ToolbarWindow32; INSTANCE:3]
ID: 1504
Text:   Infobereich des Benutzers
Position:   1366, 0
Size:   48, 40
ControlClick Coords:    12, 26
Style:  0x56008B4D
ExStyle:    0x00000080
Handle: 0x0001012E

>>>> Mouse <<<<
Position:   1378, 850
Cursor ID:  0
Color:  0xF7F7F7

>>>> StatusBar <<<<

>>>> ToolsBar <<<<
1:  1   OkayFreedom 1.7.4.12069
2:  0   Lautsprecher: 14%

>>>> Visible Text <<<<
Start
Taskansicht
Ausgeführte Anwendungen
Ausgeführte Anwendungen
Infobereich des Systems
Infobereich des Benutzers
Systemuhr, 03:04, ‎20.‎01.‎2017
Info-Center


>>>> Hidden Text <<<<
Frag mich etwas
Eingabeindikator für Taskleiste

how can i controlclick it when i do not have a title ? i googled and i found an udf , but it didnt really help me

it has functions to count the trays and so on but what shall i do with that ?

thanks in advance.. :)

Link to comment
Share on other sites

hmm when i start your action center function it sais systray not found... what can be the problem ? im sry i dont really understand what funciton you mean in this udf that can help me out.. is it the function where i can get the $hwnd ? but how do i use it then to click a menu item? i mean the click on the vpn symbol isnt all, the menu opens then and i want it to click on turn off vpn

Edited by sonic208
Link to comment
Share on other sites

hey subz thank you very much . the click works now, but i still couldnt figure out how to click something in the menu ? where can i find the examples ? is it here somewhere and i cant see it ?

"Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd""  
1: Title is: <> Class   := <SysPager>   controltype:= <UIA_PaneControlTypeId>   ,<50033>    , (0000C371)    1366;824;48;40
"Title:=;controltype:=UIA_PaneControlTypeId;class:=SysPager""   
0: Title is: <Infobereich des Benutzers>    Class   := <ToolbarWindow32>    controltype:= <UIA_ToolBarControlTypeId>    ,<50021>    , (0000C365)    1366;824;48;40
"Title:=Infobereich des Benutzers;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32""    


;~ *** Standard code maintainable ***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

_UIA_setVar("oP1","Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd")    ;
_UIA_setVar("oP2","Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd")    ;
_UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=SysPager") ;
_UIA_setVar("oP4","Title:=Infobereich des Benutzers;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32")  ;Infobereich des Benutzers

;~ $oUIElement=_UIA_getObjectByFindAll("OkayFreedom1.7.4.12069.mainwindow", "title:=OkayFreedom 1.7.4.12069;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=OkayFreedom 1.7.4.12069;controltype:=UIA_ButtonControlTypeId;class:=") ;ControlType:=UIA_ButtonControlTypeId;classname:=")

;~ Actions split away from logical/technical definition above can come from configfiles 

;~_UIA_Action("oP1","highlight")
_UIA_Action("oP1","setfocus")
;~_UIA_Action("oP2","highlight")
_UIA_Action("oP2","setfocus")
;~_UIA_Action("oP3","highlight")
_UIA_Action("oP3","setfocus")
;~_UIA_Action("oP4","highlight")
_UIA_Action("oP4","setfocus")

;~_UIA_action($oUIElement","highlight")
;~_UIA_action($oUIElement,"click")
;~_UIA_action("oUIElement","highlight")
;~_UIA_action("oUIElement","click")


;~ *** Standard code Flexible***
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)

Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)   
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd", $treescope_children)    
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=SysPager", $treescope_children) 
_UIA_Action($oP1,"setfocus")
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Infobereich des Benutzers;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32", $treescope_children)  
_UIA_Action($oP0,"setfocus")
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("OkayFreedom1.7.4.12069.mainwindow", "title:=OkayFreedom 1.7.4.12069;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=OkayFreedom 1.7.4.12069;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
;~_UIA_action($oUIElement,"highlight")
_UIA_action($oUIElement,"click")


*** Detailed properties of the highlighted element ***
UIA_title:= <OkayFreedom 1.7.4.12069>
UIA_text:= <OkayFreedom 1.7.4.12069>
UIA_regexptitle:= <OkayFreedom 1.7.4.12069>
UIA_iaccessiblechildId:= <1>
UIA_handle:= <0>
UIA_RuntimeId:= <42;65834;2;-2147483647;65834;-4;1>
UIA_BoundingRectangle:= <1366;824;24;40>
UIA_ProcessId:= <80452>
UIA_ControlType:= <50000>
UIA_LocalizedControlType:= <Schaltfläche>
UIA_Name:= <OkayFreedom 1.7.4.12069>
UIA_HasKeyboardFocus:= <False>
UIA_IsKeyboardFocusable:= <False>
UIA_IsEnabled:= <True>
UIA_Culture:= <0>
UIA_IsControlElement:= <True>
UIA_IsContentElement:= <True>
UIA_IsPassword:= <False>
UIA_NativeWindowHandle:= <0>
UIA_IsOffscreen:= <False>
UIA_Orientation:= <0>
UIA_IsRequiredForForm:= <False>
UIA_IsDockPatternAvailable:= <False>
UIA_IsExpandCollapsePatternAvailable:= <False>
UIA_IsGridItemPatternAvailable:= <False>
UIA_IsGridPatternAvailable:= <False>
UIA_IsInvokePatternAvailable:= <True>
UIA_IsMultipleViewPatternAvailable:= <False>
UIA_IsRangeValuePatternAvailable:= <False>
UIA_IsScrollPatternAvailable:= <False>
UIA_IsScrollItemPatternAvailable:= <False>
UIA_IsSelectionItemPatternAvailable:= <False>
UIA_IsSelectionPatternAvailable:= <False>
UIA_IsTablePatternAvailable:= <False>
UIA_IsTableItemPatternAvailable:= <False>
UIA_IsTextPatternAvailable:= <False>
UIA_IsTogglePatternAvailable:= <False>
UIA_IsTransformPatternAvailable:= <False>
UIA_IsValuePatternAvailable:= <False>
UIA_IsWindowPatternAvailable:= <False>
UIA_ValueIsReadOnly:= <True>
UIA_RangeValueValue:= <0>
UIA_RangeValueIsReadOnly:= <True>
UIA_RangeValueMinimum:= <0>
UIA_RangeValueMaximum:= <0>
UIA_RangeValueLargeChange:= <0>
UIA_RangeValueSmallChange:= <0>
UIA_ScrollHorizontalScrollPercent:= <0>
UIA_ScrollHorizontalViewSize:= <100>
UIA_ScrollVerticalScrollPercent:= <0>
UIA_ScrollVerticalViewSize:= <100>
UIA_ScrollHorizontallyScrollable:= <False>
UIA_ScrollVerticallyScrollable:= <False>
UIA_SelectionCanSelectMultiple:= <False>
UIA_SelectionIsSelectionRequired:= <False>
UIA_GridRowCount:= <0>
UIA_GridColumnCount:= <0>
UIA_GridItemRow:= <0>
UIA_GridItemColumn:= <0>
UIA_GridItemRowSpan:= <1>
UIA_GridItemColumnSpan:= <1>
UIA_DockDockPosition:= <5>
UIA_ExpandCollapseExpandCollapseState:= <3>
UIA_MultipleViewCurrentView:= <0>
UIA_WindowCanMaximize:= <False>
UIA_WindowCanMinimize:= <False>
UIA_WindowWindowVisualState:= <0>
UIA_WindowWindowInteractionState:= <0>
UIA_WindowIsModal:= <False>
UIA_WindowIsTopmost:= <False>
UIA_SelectionItemIsSelected:= <False>
UIA_TableRowOrColumnMajor:= <2>
UIA_ToggleToggleState:= <2>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <1>
UIA_LegacyIAccessibleName:= <OkayFreedom 1.7.4.12069>
UIA_LegacyIAccessibleRole:= <43>
UIA_LegacyIAccessibleState:= <128>
UIA_LegacyIAccessibleDefaultAction:= <Drücken>
UIA_IsDataValidForForm:= <False>
UIA_ProviderDescription:= <[pid:80452,hwnd:0x0 Annotation:Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main(parent link):Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

 

Link to comment
Share on other sites

@sonic208 - Here are the steps I used for my VPN:

Run Simple UIA Spy
Place your Mouse cursor over the System Tray VPN Icon
Press: Ctrl+W
Copy either the "Standard code maintainable" or the "Standard code Flexible" to a new Au3 File from the Simple Spy console.
nb: I found the "Standard code Flexible" worked for me

Right Click: VPN Icon in System Tray
Press: Ctrl+W with your mouse over the VPN menu item you wish to click
Copy either the "Standard code maintainable" or the "Standard code Flexible" to the Au3 File you created above from the Simple Spy console.

You need to combine both codes here is my combined code (with comments removed):

;~ *** Standard code Flexible*** - Hover over System Tray Icon
#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)
Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd", $treescope_children)
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=SysPager", $treescope_children)
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=User Promoted Notification Area;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32", $treescope_children)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Cisco AnyConnect Secure Mobility Client;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"rightclick")

;~ *** Standard code Flexible*** - Selecting System Tray Icon Menu Item
Local $oP0=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Context;controltype:=UIA_MenuControlTypeId;class:=#32768", $treescope_children)
_UIA_Action($oP0,"setfocus")
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=About;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
_UIA_action($oUIElement,"click")

 

Simple UIA Spy.jpg

Link to comment
Share on other sites

omg im sorry that i asked you such a silly question... i should have got the idea by my own :D:D But thank you very much buddy for your detailed answers !!! ill try it out now i hope there wont be any unexpected error :D thx thx thx

 

EDIT: it almost works perfect, but why are there appearing red squares onmy desktop ? :) but the more important question is this is now like a control click right ?  so if i use the mouse somewhere else it wont be affected ? :)

#include "UIAWrappers.au3"
AutoItSetOption("MustDeclareVars", 1)



AutoItSetOption("MustDeclareVars", 1)

Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Shell_TrayWnd", $treescope_children)

Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_PaneControlTypeId;class:=TrayNotifyWnd", $treescope_children)

Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=SysPager", $treescope_children)

Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=Infobereich des Benutzers;controltype:=UIA_ToolBarControlTypeId;class:=ToolbarWindow32", $treescope_children)

;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("OkayFreedom1.7.4.12069.mainwindow", "title:=OkayFreedom 1.7.4.12069;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=OkayFreedom 1.7.4.12069;ControlType:=UIA_ButtonControlTypeId", $treescope_subtree)

_UIA_action($oUIElement,"click")
Local $oP0=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Kontextmenü;controltype:=UIA_MenuControlTypeId;class:=#32768", $treescope_children)

;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll(".mainwindow", "title:=;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=;ControlType:=UIA_MenuItemControlTypeId", $treescope_subtree)
;~_UIA_action($oUIElement,"highlight")
_UIA_action($oUIElement,"click")

 

Edited by sonic208
Link to comment
Share on other sites

No problem :)

To remove the red squares I found that you add _UIA_setVar("Global.Highlight", False) just below AutoItSetOption(...

With regards to the mouse movement it appears to be more like MouseClick rather than ControlClick unfortunately I haven't used the UDF that often to give you more information on this, I assume you could save the position of the mouse before it does its thing and then return it to the original position.  @junkew who wrote the UDF might be able to give you more details on the process.

Link to comment
Share on other sites

highlighting is by default true as most of the times that makes life easier when you are misdetecting your controls in the complex hierarchy of controls.

moving mouse cursor is highly dependent on the control supporting invoke yes/no

_UIA_action($oUIElement,"invoke")

is implemented like this

Case "invoke"
            $obj2ActOn.setfocus()
            Sleep($UIA_DefaultWaitTime)
            $tPattern = _UIA_getPattern($obj2ActOn, $UIA_InvokePatternId)
            $tPattern.invoke()

and the

"leftclick", "left", "click", "leftdoubleclick", "leftdouble", "doubleclick",  "rightclick", "right",  "rightdoubleclick", "rightdouble",  "middleclick", "middle",  "middledoubleclick", "middledouble",  "mousemove", "movemouse"

are all using 

;~          Mouse should move to keep it as userlike as possible
            MouseMove($x, $y, 0)
;~          mouseclick($clickAction,Default,Default,$clickCount,0)
            If Not StringInStr($strAction, "move") Then
                MouseClick($clickAction, $x, $y, $clickCount, 0)
            EndIf

Why should the mouse not move? I can remember starting x,y and set it back after clicking but to me that sounds not adding any value

If you want that you have to fallback to sendmessage functions which are not allways equally reliable or consistent
https://msdn.microsoft.com/en-us/library/windows/desktop/bb775985(v=vs.85).aspx

SendMessage( HWND, BM_CLICK, 0, 0);
Edited by junkew
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...