junkew

IUIAutomation MS framework automate chrome, FF, IE, ....

600 posts in this topic

#581 ·  Posted

I am just glad that I found a workaround anyway. From the chrominum docs:

Quote
  • MSAA/IAccessible (complete)
  • IAccessible2 (mostly complete)
  • ISimpleDOM (mostly complete)
  • IAccessibleEx and UI Automation (very limited)

UI Automation support is very limited. So it makes sense why chrome has different results when using treewalkers and findall. Looks like I am sticking with my function :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites



#582 ·  Posted

12 hours ago, TheDcoder said:

_UIA_getObjectByFindAll cannot find it

Because you find by $treescope_children (default). Try this

$oMuteButton = _UIA_getObjectByFindAll($oChrome, 'LegacyIAccessibleName:=Mute;ControlType:=UIA_ButtonControlTypeId', $treescope_subtree)

 

3 hours ago, junkew said:

When I try with youtube and simplespy the LegacyIAccessibleName is NOT coming for mute but it is filled for play button

If mouse cursor is over "mute" button, then LegacyIAccessible.Name of "mute" button is empty. But if you move mouse cursor from "mute" button, then LegacyIAccessible.Name will be "Mute".

1 person likes this

Share this post


Link to post
Share on other sites

#583 ·  Posted

3 minutes ago, InnI said:

Because you find by $treescope_children (default).

It worked :blink:. Thanks for the advice, I did play around with the $treescope constants but I didn't try the subtree option... I must have been very tired, thanks again! :thumbsup:


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#584 ·  Posted (edited)

Hi, sorry for my english...

i am testing the ex04 with the calculator  so i have put the french name of different key in the prog ex04 (following the dump inside log)

 

so i have the error with the result (key =) .. following the dump, the key is "Résultat" but i have this error in log...

<logline level="5" timestamp="20171015-201912548"> Matching name transformed to propertynumber: 30005: for having value 1</logline>
<logline level="5" timestamp="20171015-201912564"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201912736"> Matching name transformed to propertynumber: 30005: for having value Additionner</logline>
<logline level="5" timestamp="20171015-201912765"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201912970"> Matching name transformed to propertynumber: 30005: for having value 3</logline>
<logline level="5" timestamp="20171015-201913011"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201913171"> Matching name transformed to propertynumber: 30005: for having value Résultat</logline>
<logline level="5" timestamp="20171015-201913174"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201913317"> UIA WARNING ** NOT ** found the pattern</logline>
</log>

so maybe the cause is the "é" ?

 

thanks for help

Terry

 

EDIT: problem resolved... in fact the name is not Résultat.... i have used UIspu.exe and i have had the right name.. "Est égal à"

Edited by Frenchy
problem relsoved

Share this post


Link to post
Share on other sites

#585 ·  Posted

23 hours ago, Frenchy said:

Hi, sorry for my english...

i am testing the ex04 with the calculator  so i have put the french name of different key in the prog ex04 (following the dump inside log)

 

so i have the error with the result (key =) .. following the dump, the key is "Résultat" but i have this error in log...

<logline level="5" timestamp="20171015-201912548"> Matching name transformed to propertynumber: 30005: for having value 1</logline>
<logline level="5" timestamp="20171015-201912564"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201912736"> Matching name transformed to propertynumber: 30005: for having value Additionner</logline>
<logline level="5" timestamp="20171015-201912765"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201912970"> Matching name transformed to propertynumber: 30005: for having value 3</logline>
<logline level="5" timestamp="20171015-201913011"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201913171"> Matching name transformed to propertynumber: 30005: for having value Résultat</logline>
<logline level="5" timestamp="20171015-201913174"> UIA found the element</logline>
<logline level="5" timestamp="20171015-201913317"> UIA WARNING ** NOT ** found the pattern</logline>
</log>

so maybe the cause is the "é" ?

 

thanks for help

Terry

 

EDIT: problem resolved... in fact the name is not Résultat.... i have used UIspu.exe and i have had the right name.. "Est égal à"

Simplespy should give the values also. If not let me know as that would be ineresting then to understand.

Share this post


Link to post
Share on other sites

#586 ·  Posted

The latest version of SimpleSpy is crashing on this line under some circumstances

$oTW.getparentelement($oUIElement,$pTMPParentHandle)

See this thread for details.

 

Share this post


Link to post
Share on other sites

#588 ·  Posted

Yes, that does resolve the issue. Seems like there should still be a way to prevent the program from this hard crash.

Share this post


Link to post
Share on other sites

#589 ·  Posted

 

Hello, I have to use this udf in a windows xp. When I use control+w of the simplepy it gives me this error:

Quote

/TODO codetemplates.txt not available An error occurred when reading the file. & @CRLF"C:\Documents and Settings\Administrador\Mis documentos\UIA_V0\UIA_V0_51\simplespy.au3" (86) : ==> Variable must be of type "Object".:
$UIA_oUIAutomation.ElementFromPoint($tStruct,$UIA_pUIElement )
$UIA_oUIAutomation^ ERROR

I have framework .net 4.0 installed. I have not been able to install the program of link https://support.microsoft.com/es-es/help/971513/description-of-the-windows-automation-api . The link to xp is broken. How can I run ui automation on windows xp? I need to install something? Where can I download it?

Thank you very much.

Share this post


Link to post
Share on other sites

#591 ·  Posted

helloo guys!

so i needed something good and i found ff.au3.

it worked, but now its not. it cant find opened window, and because of it nothing else works.

WHY???

i mean when i start program with ffopenurl, same happens, cant find the given url as an opened window! WHY????????

Share this post


Link to post
Share on other sites

#592 ·  Posted

ok the standard connect example also does not work, most fresh firefox client. so i have nothing to access to my browsers.. nice work!

ie does not handle webpages, ff does not accessible from ff.au3.

any good news?:D

 

Share this post


Link to post
Share on other sites

#593 ·  Posted

as i can see the program standrardly cant find opened url tab, and it cant receive regedit data about firefox.. maybe newer versions are using different reg keys or smth like this, and ff.au3 cant access the program. mozrepl works, it can communicate, but nothing more..

so this also FAIL!

Share this post


Link to post
Share on other sites

#594 ·  Posted

There's a separate thread for FF.au3 so unsure why you are posting about it here. FWIW, it still works, but only on older versions of FF such as 54.x. The MozRepl add-on doesn't work with later versions of FF. Therefore, the FF.au3 UDF no longer works with the latest FF.

Since you are posting in the IUIAutomation thread, have you tried using this UDF for your automation needs?

Share this post


Link to post
Share on other sites

#596 ·  Posted

Hello,

A bit off topic, but I found this forum and trying to implement it in a script for Outlook O365 set-up but at a complete loss.  I need to read if the "Set up Outlook Mobile on my phone, too" is checked, if it is checked then un-check.

Here is the simplespy output...

https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/?do=findComment&comment=1156373
At least we have an element title: [Set up Outlook Mobile on my phone, too] class: []

Having the following values for all properties: 
Title is: <Set up Outlook Mobile on my phone, too>    Class   := <>    controltype:= <UIA_CheckBoxControlTypeId>    ,<50002>    , (0000C352)    800;331;239;19
*** Parent Information top down ***
3: Title is: <Welcome to Outlook>    Class   := <NUIDialog>    controltype:= <UIA_WindowControlTypeId>    ,<50032>    , (0000C370)    520;46;800;468
"Title:=Welcome to Outlook;controltype:=UIA_WindowControlTypeId;class:=NUIDialog""    
2: Title is: <Welcome to Outlook>    Class   := <NetUIHWND>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    521;69;798;444
"Title:=Welcome to Outlook;controltype:=UIA_PaneControlTypeId;class:=NetUIHWND""    
1: Title is: <>    Class   := <>    controltype:= <UIA_PaneControlTypeId>    ,<50033>    , (0000C371)    521;69;798;444
"Title:=;controltype:=UIA_PaneControlTypeId;class:=""    
0: Title is: <>    Class   := <>    controltype:= <UIA_CustomControlTypeId>    ,<50025>    , (0000C369)    521;69;798;444
"Title:=;controltype:=UIA_CustomControlTypeId;class:=""    


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

_UIA_setVar("oP1","Title:=Welcome to Outlook;controltype:=UIA_WindowControlTypeId;class:=NUIDialog")    ;Welcome to Outlook
_UIA_setVar("oP2","Title:=Welcome to Outlook;controltype:=UIA_PaneControlTypeId;class:=NetUIHWND")    ;Welcome to Outlook
_UIA_setVar("oP3","Title:=;controltype:=UIA_PaneControlTypeId;class:=")    ;
_UIA_setVar("oP4","Title:=;controltype:=UIA_CustomControlTypeId;class:=")    ;

;~ $oUIElement=_UIA_getObjectByFindAll("SetupOutlookMobileonmyphone,too.mainwindow", "title:=Set up Outlook Mobile on my phone, too;ControlType:=UIA_CheckBoxControlTypeId", $treescope_subtree)
_UIA_setVar("oUIElement","Title:=Set up Outlook Mobile on my phone, too;controltype:=UIA_CheckBoxControlTypeId;class:=") ;ControlType:=UIA_CheckBoxControlTypeId;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")


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

Local $oP3=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=Welcome to Outlook;controltype:=UIA_WindowControlTypeId;class:=NUIDialog", $treescope_children)    
_UIA_Action($oP3,"setfocus")
Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=Welcome to Outlook;controltype:=UIA_PaneControlTypeId;class:=NetUIHWND", $treescope_children)    
_UIA_Action($oP2,"setfocus")
Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=;controltype:=UIA_PaneControlTypeId;class:=", $treescope_children)    
Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_CustomControlTypeId;class:=", $treescope_children)    
;~ First find the object in the parent before you can do something
;~$oUIElement=_UIA_getObjectByFindAll("SetupOutlookMobileonmyphone,too.mainwindow", "title:=Set up Outlook Mobile on my phone, too;ControlType:=UIA_CheckBoxControlTypeId", $treescope_subtree)
Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=Set up Outlook Mobile on my phone, too;ControlType:=UIA_CheckBoxControlTypeId", $treescope_subtree)
;~_UIA_action($oUIElement,"highlight")
_UIA_action($oUIElement,"click")


*** Detailed properties of the highlighted element ***
UIA_title:= <Set up Outlook Mobile on my phone, too>
UIA_text:= <Set up Outlook Mobile on my phone, too>
UIA_regexptitle:= <Set up Outlook Mobile on my phone, too>
UIA_iaccessiblechildId:= <0>
UIA_handle:= <0>
UIA_BoundingRectangle:= <800;331;239;19>
UIA_ProcessId:= <10724>
UIA_ControlType:= <50002>
UIA_LocalizedControlType:= <check box>
UIA_Name:= <Set up Outlook Mobile on my phone, too>
UIA_HasKeyboardFocus:= <True>
UIA_IsKeyboardFocusable:= <True>
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:= <True>
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:= <1>
UIA_TransformCanMove:= <False>
UIA_TransformCanResize:= <False>
UIA_TransformCanRotate:= <False>
UIA_IsLegacyIAccessiblePatternAvailable:= <True>
UIA_LegacyIAccessibleChildId:= <0>
UIA_LegacyIAccessibleName:= <Set up Outlook Mobile on my phone, too>
UIA_LegacyIAccessibleRole:= <44>
UIA_LegacyIAccessibleState:= <1048596>
UIA_LegacyIAccessibleDefaultAction:= <Uncheck>
UIA_IsDataValidForForm:= <False>
UIA_ProviderDescription:= <[pid:10724,hwnd:0x0 Main(parent link):Microsoft: MSAA Proxy (unmanaged:UIAutomationCore.DLL)]>
UIA_IsItemContainerPatternAvailable:= <False>
UIA_IsVirtualizedItemPatternAvailable:= <False>
UIA_IsSynchronizedInputPatternAvailable:= <False>

I can right now just do the action to click on it..

#include "UIAWrappers.au3"

_UIA_setVar("RTI.SEARCHCONTEXT", $UIA_oDesktop)

$oP0=_UIA_action("title:=Set up Outlook Mobile on my phone, too;ControlType:=UIA_CheckBoxControlTypeId", "getobject")
_UIA_action($oP0,"click")
 

Please help and Thanks!!

 

 

Share this post


Link to post
Share on other sites

Hi there, 

 

first of all: Thank you for this awesome set of wrapper functions, it's awesome what you can do with it. I've been working with AutoIt for fun for quite a while now, and stumbled across this by accident. Keep up the good work!

Still, I found an issue within Func uia_action(...)

 Given:

While True
    $result = _UIA_action($myObj, "getValue")
    FileWrite($myFile, $result)
WEnd

$result will sometimes be empty, as it appears that the clipboard requires more time to handle the new information given by Send(^c), so ClipGet() will return "".

From UIAWrappers.au3:

Case "getValue"
            $obj2ActOn.setfocus()
            Send("^a")
            Send("^c")
            $retValue = ClipGet()

 

I solved this by adding a static sleep in there:

Case "getValue"
            $obj2ActOn.setfocus()
            Send("^a")
            Send("^c")
            Sleep(100)
            $retValue = ClipGet()

Still, if the clipboard is busy by whatsoever, this will not solve the issue. I am not sure if there is a more sophisticated way to handle this?

Thanks and Regards!

Share this post


Link to post
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

  • Similar Content

    • bobmcrae
      By bobmcrae
      I am experimenting with UIAWrappers.au3 from junkew to complete an application which presents absolutely no control information using AutoIT Window Info.  While I am able to complete the form successfully, I am not happy with the speed.  As a benchmark, the simple Send method occurs in far less than 1-second, but the UIAutomation approach takes 3-seconds.  I am wondering whether performance gains may be achieved by specifying the controls more precisely; but I am unsure how to do that.  I was able to speed things up a bit by setting $UIA_DefaultWaitTime=0.  The controls of interest are 5-levels deep, as show in the simplespy output below.  It seems I do get faster response by specifying the target/top-level window, as show in the code below.  Any ideas?
      #include "UIAWrappers.au3" _UIA_setVar("Global.Debug", False) _UIA_setVar("Global.Debug.File", False) _UIA_setVar("Global.Highlight", False) _UIA_setVar("DPN","Title:=NC-stat DPNCheck Communicator;controltype:=UIA_WindowControlTypeId;class:=Window") _UIA_action('DPN','setFocus') _UIA_setVar("DPN.firstName","AutomationId:=txtFirstName") _UIA_setVar("DPN.lastName", "AutomationId:=txtLastName") _UIA_Action('DPN.lastName','setvalue','last name') _UIA_setVar("DPN.ID", "AutomationId:=txtSubjectId") _UIA_setVar("DPN.DOB", "AutomationId:=PART_TextBox") _UIA_setVar("DPN.Ft", "AutomationId:=txtSubjectHeight") _UIA_setVar("DPN.In", "AutomationId:=txtSubjectHeight2") _UIA_Action('DPN.firstName','setvalue','first name') _UIA_Action('DPN.ID','setvalue','ID012345') _UIA_Action('DPN.DOB','setvalue','1/31/1932') _UIA_Action('DPN.Ft','setvalue','6') _UIA_Action('DPN.In','setvalue','1') SimpleSpy output:
      ;~ *** Standard code *** #include "UIAWrappers.au3" AutoItSetOption("MustDeclareVars", 1) Local $oP4=_UIA_getObjectByFindAll($UIA_oDesktop, "Title:=NC-stat DPNCheck Communicator;controltype:=UIA_WindowControlTypeId;class:=Window", $treescope_children) _UIA_Action($oP4,"setfocus") Local $oP3=_UIA_getObjectByFindAll($oP4, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Frame", $treescope_children) Local $oP2=_UIA_getObjectByFindAll($oP3, "Title:=;controltype:=UIA_TabControlTypeId;class:=TabControl", $treescope_children) Local $oP1=_UIA_getObjectByFindAll($oP2, "Title:=Patient;controltype:=UIA_TabItemControlTypeId;class:=TabItem", $treescope_children) Local $oP0=_UIA_getObjectByFindAll($oP1, "Title:=;controltype:=UIA_PaneControlTypeId;class:=Frame", $treescope_children) ;~ First find the object in the parent before you can do something ;~$oUIElement=_UIA_getObjectByFindAll(".mainwindow", "title:=;ControlType:=UIA_EditControlTypeId", $treescope_subtree) Local $oUIElement=_UIA_getObjectByFindAll($oP0, "title:=;ControlType:=UIA_EditControlTypeId", $treescope_subtree) _UIA_action($oUIElement,"click")  
    • jackchen
      By jackchen
      OK,I've made my "Chrome_KeepLastTab.au3" work.This script adds some features to Chrome browser:
      1. Double click on a tab to close the tab.
      2. Keep last tab:This script monitors your mouse clicks and hotkeys,if you are about to close the last tab within Chrome(click close button on the last tab, middle click/double click on the last tab or press Ctrl + w or Ctrl + {F4}), a new tab will be open and then the old tab be closed.
      #include <WindowsConstants.au3> #include <WinAPI.au3> #include "CUIAutomation2.au3" #AutoIt3Wrapper_UseX64=Y ;Should be used for stuff like tagpoint having right struct etc. when running on a 64 bits os ConsoleWrite("@OSArch: " & @OSArch & ", @AutoItX64: " & @AutoItX64 & @CRLF) Global $DoubleClickTime = 500 Global $UIA_oUIAutomation ; The main library core CUI automation reference Global $hMouseEvent, $hMouseHook Global $aMouseEvent[2] Global $KeepLastTab = True ; settings from ini file If $KeepLastTab Then ;The main object with acces to the windows automation api 3.0 $UIA_oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If IsObj($UIA_oUIAutomation) Then HotKeySet("^w", "Hotkey_Event") ; Ctrl + w to close tab HotKeySet("^{F4}", "Hotkey_Event") ; Ctrl + {F4} to close tab $DoubleClickTime = DllCall("user32.dll", "uint", "GetDoubleClickTime")[0] OnAutoItExitRegister("UnhookMouse") ; Register mouse events callback $hMouseEvent = DllCallbackRegister("Mouse_Event", "int", "int;ptr;ptr") $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseEvent), _WinAPI_GetModuleHandle(0)) EndIf EndIf While 1 Sleep(100) WEnd ToolTip("") ; https://www.autoitscript.com/forum/topic/103362-monitoring-mouse-events/ Func Mouse_Event($nCode, $wParam, $lParam) Local $info, $mouseData, $time, $timeDiff If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ; Continue processing EndIf $tPoint = _WinAPI_GetMousePos() $hWnd = _WinAPI_WindowFromPoint($tPoint) ; if mouse is on the widget window(class: Chrome_RenderWidgetHostHWND), ; use $hWnd = _WinAPI_GetParent($hWnd) to get the parent Chrome window If Not StringInStr(_WinAPI_GetClassName($hWnd), "Chrome_WidgetWin_") Then ; Chrome_WidgetWin_1: Chrome window ; Chrome_WidgetWin_2: Chrome menu ; ignore non Chrome window Return _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) EndIf ToolTip($hWnd & " - " & _WinAPI_GetClassName($hWnd)) ;$tagPOINT = "struct;long X;long Y;endstruct" Local Const $MSLLHOOKSTRUCT = $tagPOINT & ";dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo" $info = DllStructCreate($MSLLHOOKSTRUCT, $lParam) $mouseData = DllStructGetData($info, 3) $time = DllStructGetData($info, 5) $timeDiff = $time - $aMouseEvent[1] Local $block Switch $wParam Case $WM_LBUTTONUP $aMouseEvent[1] = $time If $aMouseEvent[0] = "LClick" And ($timeDiff) < $DoubleClickTime Then $aMouseEvent[0] = "LDClick" Else $aMouseEvent[0] = "LClick" EndIf $block = KeepLastTab($hWnd, $aMouseEvent[0]) Case $WM_MBUTTONUP $aMouseEvent[1] = $time If $aMouseEvent[0] = "MClick" And ($timeDiff) < $DoubleClickTime Then $aMouseEvent[0] = "MDClick" Else $aMouseEvent[0] = "MClick" $block = KeepLastTab($hWnd, $aMouseEvent[0]) EndIf EndSwitch If Not $block Then _WinAPI_CallNextHookEx($hMouseHook, $nCode, $wParam, $lParam) ; Continue processing EndIf EndFunc ;==>Mouse_Event Func UnhookMouse() _WinAPI_UnhookWindowsHookEx($hMouseHook) $hMouseHook = 0 DllCallbackFree($hMouseEvent) $hMouseEvent = 0 EndFunc ;==>UnhookMouse Func Hotkey_Event() Local $block Local $hWnd = WinGetHandle(WinGetTitle("[ACTIVE]")) If StringInStr(_WinAPI_GetClassName($hWnd), "Chrome_WidgetWin_1") Then ; Chrome_WidgetWin_1, Chrome window $block = KeepLastTab($hWnd, "Hotkey") EndIf If Not $block Then HotKeySet("^w") Send(@HotKeyPressed) HotKeySet("^w", "Hotkey_Event") EndIf EndFunc Func KeepLastTab($hWnd, $action = "LClick") ; Possible $action value: LClick, LDClick, MClick, Hotkey ConsoleWrite(@CRLF & $action & " on a Chrome window: " & $hWnd & @CRLF) Local $aMousePos = MouseGetPos() Local $pChrome, $oChrome $UIA_oUIAutomation.ElementFromHandle($hWnd, $pChrome) ; Window $oChrome = ObjCreateInterface($pChrome, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oChrome) Then ConsoleWrite("Failed to get Chrome object from hWnd." & @CRLF) Return EndIf ;$UIA_ControlTypePropertyId = 30003 $oChromeTabs = UIA_getFirstElement($oChrome, $UIA_ControlTypePropertyId, $UIA_TabControlTypeId, $treescope_subtree) If Not IsObj($oChromeTabs) Then ConsoleWrite("Failed to get Chrome tab bar object." & @CRLF) Return EndIf Local $t $oChromeTabs.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, $t) If UBound($t) < 4 Then Return If $action <> "Hotkey" And ($aMousePos[0] < $t[0] Or $aMousePos[0] > $t[2]+$t[0] Or $aMousePos[1] < $t[1] Or $aMousePos[1] > $t[3]+$t[1]) Then ; Mouse not on tabs bar ConsoleWrite("Mouse is not on the tab bar. Ignore and return..." & @CRLF) Return EndIf Local $pTrueCondition, $pElements, $iLength, $oAutomationElementArray $UIA_oUIAutomation.CreateTrueCondition($pTrueCondition) $oCondition = ObjCreateInterface($pTrueCondition, $sIID_IUIAutomationCondition, $dtagIUIAutomationCondition) If Not IsObj($oCondition) Then Return $oChromeTabs.FindAll($treescope_children, $oCondition, $pElements) $oAutomationElementArray = ObjCreateInterface($pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) If Not IsObj($oAutomationElementArray) Then ConsoleWrite("Failed to find all Chrome tabs. " & @CRLF) Return EndIf $oAutomationElementArray.Length($iLength) Local $UIA_pUIElement, $oTab2 Local $iTabs = $iLength - 1 If $iTabs > 1 Then ; more than one tab If $action = "LDClick" Then ConsoleWrite("There are " & $iTabs & " tabs within Chrome window. " & @CRLF) For $i = 1 To $iTabs $oAutomationElementArray.GetElement($i, $UIA_pUIElement) $oTab2 = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oTab2) Then ContinueLoop $oTab2.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, $t) If UBound($t) < 4 Then ContinueLoop If $aMousePos[0] >= $t[0] And $aMousePos[0] <= $t[2]+$t[0] And $aMousePos[1] >= $t[1] And $aMousePos[1] <= $t[3]+$t[1] Then ConsoleWrite("You double clicked on one of " & $iTabs & " tabs. Close the tab and return..." & @CRLF) HotKeySet("^w") Send("^w") HotKeySet("^w", "Hotkey_Event") Return True EndIf Next EndIf Return EndIf ConsoleWrite("There is ONLY one tab within Chrome window. " & @CRLF) $oAutomationElementArray.GetElement(1, $UIA_pUIElement) $oTab = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oTab) Then ConsoleWrite("Failed to get the last tab object." & @CRLF) Return EndIf Local $rtTab $oTab.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, $rtTab) If UBound($rtTab) < 4 Then Return If $action <> "Hotkey" And ($aMousePos[0] < $rtTab[0] Or $aMousePos[0] > $rtTab[2]+$rtTab[0] Or $aMousePos[1] < $rtTab[1] Or $aMousePos[1] > $rtTab[3]+$rtTab[1]) Then ; Mouse not on the last tab ConsoleWrite("Mouse is not on the last tab. Ignore and return..." & @CRLF) Return EndIf If $action = "LClick" Then $oTabClose = UIA_getFirstElement($oTab, $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $treescope_subtree) If Not IsObj($oTabClose) Then ConsoleWrite("Failed to get the last tab close object." & @CRLF) Return EndIf $oTabClose.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, $t) If UBound($t) < 4 Then Return If $aMousePos[0] < $t[0] Or $aMousePos[0] > $t[2]+$t[0] Or $aMousePos[1] < $t[1] Or $aMousePos[1] > $t[3]+$t[1] Then ; Mouse not on the tab close button Return EndIf EndIf ; open a new tab within chrome ConsoleWrite("The last tab is about to be closed, so we have to open a new tab to prevent Chrome window from closing." & @CRLF) Send("^t") ConsoleWrite("A new tab created!" & @CRLF) Sleep(100) ConsoleWrite("Close the old tab and return..." & @CRLF) ;~ Local $pPattern ;~ $oTabClose.GetCurrentPattern($UIA_InvokePatternId, $pPattern) ;~ $oPattern = ObjCreateInterface($pPattern, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern) ;~ If IsObj($oPattern) Then ;~ ConsoleWrite("Invoke to close the tab..." & @CRLF) ;~ $oTabClose.SetFocus() ;~ $oPattern.Invoke() ;~ EndIf _WinAPI_UnhookWindowsHookEx($hMouseHook) $aMousePos = MouseGetPos() If $aMousePos[0] >= $rtTab[0] And $aMousePos[0] <= $rtTab[2]+$rtTab[0] And $aMousePos[1] >= $rtTab[1] And $aMousePos[1] <= $rtTab[3]+$rtTab[1] Then MouseClick("middle", $aMousePos[0], $aMousePos[1], 1, 0) Else MouseClick("middle", $rtTab[0]+$rtTab[2]/2, $rtTab[1]+$rtTab[3]/2, 1, 0) ; close the tab MouseMove($aMousePos[0], $aMousePos[1], 0) ; move mouse back to previous position EndIf ;~ _WinAPI_Mouse_Event($MOUSEEVENTF_MIDDLEDOWN, $rtTab[0]+$rtTab[2]/2, $rtTab[1]+$rtTab[3]/2) ;~ Sleep(100) ;~ _WinAPI_Mouse_Event($MOUSEEVENTF_MIDDLEUP, $rtTab[0]+$rtTab[2]/2, $rtTab[1]+$rtTab[3]/2) $hMouseHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hMouseEvent), _WinAPI_GetModuleHandle(0)) Return True ; to block mouse click/hot key EndFunc Func UIA_getFirstElement($obj, $propertyID, $tval, $treeScope) Local $pCondition, $oCondition $UIA_oUIAutomation.CreatePropertyCondition($propertyID, $tval, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) Local $UIA_oUIElement, $UIA_pUIElement $t = $obj.Findfirst($treeScope, $oCondition, $UIA_pUIElement) $UIA_oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If IsObj($UIA_oUIElement) Then Return $UIA_oUIElement Return SetError(1, 0, "") EndFunc ;==>UIA_getFirstElement My question is related to #AutoIt3Wrapper_UseX64 when run this script on 64-bit Win 7.
      No mater I set #AutoIt3Wrapper_UseX64=Y or #AutoIt3Wrapper_UseX64=N, this script works very well on hotkey event, while mouse clicks sometimes works if #AutoIt3Wrapper_UseX64=N and sometimes works on Y. Can some one test this and finger out what's wrong?
      Info from SciTe if #AutoIt3Wrapper_UseX64=Y :
      @OSArch: X64, @AutoItX64: 1 Hotkey on a Chrome window: 0x0000000000140330 There is ONLY one tab within Chrome window. The last tab is about to be closed, so we have to open a new tab to prevent Chrome window from closing. A new tab created! Close the old tab and return... LClick on a Chrome window: 0x0000000000140330 There is ONLY one tab within Chrome window. The last tab is about to be closed, so we have to open a new tab to prevent Chrome window from closing. A new tab created! Close the old tab and return... Info if #AutoIt3Wrapper_UseX64=N or comment out this line:
      @OSArch: X64, @AutoItX64: 0 Hotkey on a Chrome window: 0x00140330 There is ONLY one tab within Chrome window. The last tab is about to be closed, so we have to open a new tab to prevent Chrome window from closing. A new tab created! Close the old tab and return... LClick on a Chrome window: 0x00140330 Failed to get Chrome tab bar object. Hotkey events and mouse click events share the same function KeepLastTab($hWnd, $action = "LClick"),Why this function triggered by hotkey works on both 32-bit and 64-bit while that triggered by mouse events failed on 32-bit autoit?