Creating COM Object Event Handler
Posted: 17 Sep 2017, 08:24
I apologize if I have missed something I've read over many hours on COM Objects and AutoHotkey.
I'm not new to Autohotkey, but my head is spinning every direction over how to do what I would like to do.
I need to create an AHK class which implements the IUIAutomationEventHandler Interface:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
I've read on these pages:
* About ComDispatch0 by @lexikos and I've also seen https://autohotkey.com/boards/viewtopic.php?f=13&t=4558:
Trying either just test or &test both are giving me back a "Pointer not valid error."
I'm sure this is all because my head is spinning. I'm more than happy to be pointed to similar code or a general "this is what your missing and here's some other code that does it correctly."
Thanks!
I'm not new to Autohotkey, but my head is spinning every direction over how to do what I would like to do.
I need to create an AHK class which implements the IUIAutomationEventHandler Interface:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
I've read on these pages:
* About ComDispatch0 by @lexikos and I've also seen https://autohotkey.com/boards/viewtopic.php?f=13&t=4558:
* ActiveScript for AutoHotkey v1.1 https://autohotkey.com/boards/viewtopic.php?f=6&t=4555So I experimented with adding native support for passing AutoHotkey objects to/from COM APIs. The cost is about 1-2KB of added size to AutoHotkey.exe (32-bit), with the following features...
My initial foray into writing an object for the event handler (just to see what was being called/done):ComObject := ComDispatch0(Object) - not needed in AutoHotkey v1.1.17+
Code: Select all
; NOTE - AHKDebug() is just a wrapper for OutputDebug % Format(...)
#Include <uia>
; global $u := new IUIAutomation
; global $e := new IUIAutomationElement
; global $c := new IUIAutomationCondition
; global $r := new IUIAutomationCacheRequest
; global $t := new IUIAutomationTreeWalker
; UIA_Window_WindowOpenedEventId 20016
UIA := new IUIAutomation
DesktopElem := new IUIAutomationElement(UIA.GetRootElement())
class UIATest {
__Get(name) {
AHKDebug("__Get({})", name)
}
__Set(name) {
AHKDebug("__Set({})", name)
}
__Call(name) {
AHKDebug("__Call({})", name)
}
}
test := new UIATest()
AHKDebug("About to AddAutomationEventHandler")
UIA.AddAutomationEventHandler( evt := UIA_Event("Window_WindowOpened")
, DesktopElem
, scope := UIA_Enum("TreeScope_Children")
, 0
, &test )
AHKDebug("After AddAutomationEventHandler")
I'm sure this is all because my head is spinning. I'm more than happy to be pointed to similar code or a general "this is what your missing and here's some other code that does it correctly."
Thanks!