Jump to content

Search the Community

Showing results for tags 'automationeventhandler'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. Hi, I am trying to catch closing of a window via the UIA. End goal is to detect closing of a Chrome's tab, but currently I am having issues with the window created with GUICreate. I have modified example from UI Automation Events . I added GUI to show issues. Inside this GUI AutomationEventHandler is attached to all buttons. There are two buttons created by the script. One displays the message while the other closes the GUI. There are also buttons from the title bar. I attached automation event handlers to those buttons too. Currently script notifies me if I click on "OK" button. If I click on any of "Close", "X" or "Minimize" button then I do not get any notification. Is it possible for the script to notify when any of the buttons mentioned above is clicked? #include "..\Includes\UIAEH_AutomationEventHandler.au3" $hMain=GUICreate("UI Automation Event Handler") $idButtonOK=GUICtrlCreateButton("OK",10,10) $idButtonClose=GUICtrlCreateButton("Close",70,10) $idOutput=GUICtrlCreateEdit("",10,35,300,300) GUISetState() UIAEH_AutomationEventHandlerCreate() If Not IsObj( $oUIAEH_AutomationEventHandler ) Then Exit ConsoleWrite( "$oUIAEH_AutomationEventHandler ERR" & @CRLF ) ConsoleWrite( "$oUIAEH_AutomationEventHandler OK" & @CRLF ) Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation) ;~ Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation8, $sIID_IUIAutomation6, $dtag_IUIAutomation6 ) If Not IsObj($oUIAutomation) Then Exit ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) Local $pIUIAutomationCacheRequest, $oIUIAutomationCacheRequest $oUIAutomation.CreateCacheRequest( $pIUIAutomationCacheRequest ) $oIUIAutomationCacheRequest = ObjCreateInterface( $pIUIAutomationCacheRequest, $sIID_IUIAutomationCacheRequest, $dtag_IUIAutomationCacheRequest ) If Not IsObj( $oIUIAutomationCacheRequest ) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest Error" & @CRLF) If $oIUIAutomationCacheRequest.AddPattern($UIA_InvokePatternId) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest.AddPattern Error" & @CRLF) If $oIUIAutomationCacheRequest.put_AutomationElementMode( $AutomationElementMode_Full) Then Exit ConsoleWrite("$oIUIAutomationCacheRequest.put_AutomationElementMode Error" & @CRLF) ;~ $pIUIAutomationCacheRequest=0 ConsoleWrite("--- Find window/control ---" & @CRLF) Local $pPane1, $oGUI $oUIAutomation.ElementFromHandle($hMain,$pPane1) $oGUI = ObjCreateInterface($pPane1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oGUI) Then Exit ConsoleWrite("$oGUI ERR" & @CRLF) ConsoleWrite("$oGUI OK" & @CRLF) Local $sNamePropperty, $sClassName1 $oGUI.GetCurrentPropertyValue($UIA_NamePropertyId, $sNamePropperty) ConsoleWrite("Name:" & $sNamePropperty & @CRLF) $oGUI.GetCurrentPropertyValue($UIA_ClassNamePropertyId, $sClassName1) ConsoleWrite("ClassName:" & $sClassName1 & @CRLF) ConsoleWrite("--- Find buttons ---" & @CRLF) Local $pCondition0 $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition0) If Not $pCondition0 Then Exit ConsoleWrite("$pCondition0 ERR" & @CRLF) ConsoleWrite("$pCondition0 OK" & @CRLF) Local $pButtons, $oButton $oGUI.FindAll($TreeScope_Descendants, $pCondition0, $pButtons) ConsoleWrite("$oGUI FindAll()" & @CRLF) Local $oUIElementArray1, $iLength1 ; $pButtons is a pointer to an UI Automation element array $oUIElementArray1 = ObjCreateInterface($pButtons, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray) $oUIElementArray1.Length($iLength1) If Not $iLength1 Then Exit ConsoleWrite("$iLength1 = 0 ERR" & @CRLF) ConsoleWrite("$iLength1 = " & $iLength1 & @CRLF) ; --- Code Snippets --- ConsoleWrite("--- Code Snippets ---" & @CRLF) Local $pElement1, $oElement1, $pCondition0 Local $sClassName1, $sLocalizedControlType1, $sName1, $hNativeWindowHandle1, $iError For $i = 0 To $iLength1 - 1 $oUIElementArray1.GetElement($i, $pElement1) $oElement1 = ObjCreateInterface($pElement1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) $oElement1.GetCurrentPropertyValue($UIA_NamePropertyId, $sName1) ConsoleWrite("$sName1 = " & $sName1 & @CRLF) ;~ $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Children, 0, $oUIAEH_AutomationEventHandler ) ;~ $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Element, 0, $oUIAEH_AutomationEventHandler ) $iError = $oUIAutomation.AddAutomationEventHandler( $UIA_Invoke_InvokedEventId, $pElement1, $TreeScope_Element, $pIUIAutomationCacheRequest, $oUIAEH_AutomationEventHandler ) If $iError Then Exit ConsoleWrite( "AddAutomationEventHandler() ERR" & @CRLF ) ConsoleWrite( "AddAutomationEventHandler() OK" & @CRLF ) Next While Sleep(10) Switch GUIGetMsg() Case -3, $idButtonClose GUIDelete($hMain) MsgBox(0,"About to exit","") Quit() Case $idButtonOK GUICtrlSetData($idOutput,"You clicked on button" & @CRLF,"a") EndSwitch WEnd Func Quit() UIAEH_AutomationEventHandlerDelete() Exit EndFunc ; This is the function that receives events Func UIAEH_AutomationEventHandler_HandleAutomationEvent( $pSelf, $pSender, $iEventId ) ; Ret: long Par: ptr;int ConsoleWrite( @CRLF & "UIAEH_AutomationEventHandler_HandleAutomationEvent: $iEventId = " & $iEventId & @CRLF ) ;~ Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) ; Windows 7 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement2, $dtag_IUIAutomationElement2 ) ; Windows 8 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement3, $dtag_IUIAutomationElement3 ) ; Windows 8.1 ;Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement4, $dtag_IUIAutomationElement4 ) ; Windows 10 First Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement9, $dtag_IUIAutomationElement9 ) ; Windows 10 Last $oSender.AddRef() GUICtrlSetData($idOutput,"InvokedEvent:" & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF,"a") ConsoleWrite( "Title = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _ "Class = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _ "Ctrl type = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _ "Ctrl name = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _ "Handle = " & "0x" & Hex( UIAEH_GetCurrentPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & _ "Value = " & UIAEH_GetCurrentPropertyValue( $oSender, $UIA_ValueValuePropertyId ) & @CRLF ) MsgBox(0,"","Invoke event") Return 0x00000000 ; $S_OK #forceref $pSelf EndFunc ; Auxiliary function (for simple properties only) ; There must be only one instance of this function Func UIAEH_GetCurrentPropertyValue( $oSender, $iPropertyId ) Local $vPropertyValue $oSender.GetCurrentPropertyValue( $iPropertyId, $vPropertyValue ) Return $vPropertyValue EndFunc
×
×
  • Create New...