GWKB2037 : Custom MSAA Event HandlingProduct: Window-Eyes
Author: Aaron Smith
Date Added: 08/16/2013
Last Modified: 08/16/2013
There may be times when you want to tell Window-Eyes to ignore specific MSAA events so that you can handle them yourself.
The first step in custom event handling is to block the interested event from Window-Eyes using the MSAAEventSource object's BlockEvent method:
Set blockFocusEvent = MSAAEventSource.BlockEvent(event_OBJECT_FOCUS, ClientInformation.ApplicationProcess)
Be sure to filter the BlockEvent accordingly so that you don't inadvertently block events for other windows or processes other than the one you're working with.
Once you have the event blocked, you'll hook it using the ConnectEvent method. The first parameter of the ConnectEvent method is the object you want to connect to. Because you're handling MSAA events, you want to connect to the MSAAEventSource object. But, like blocking events, you only want to handle the events for a particular window or process. So you'll need to filter the MSAAEventSource using, for example, the Process property:
Set myMSAAEventSource = MSAAEventSource myMSAAEventSource.Process = ClientInformation.ApplicationProcess
Now you can use ConnectEvent to hook the event you're interested in that's coming from the filtered event source:
msaaEventObjectFocus = ConnectEvent(myMSAAEventSource, "OnObjectFocus", "OnObjectFocus")
The callback for the event connection might look something like:
Sub OnObjectFocus(accObj) handledEvent = False If Not accObj Is Nothing Then accObj.Prefetch apAll If accObj.Name = "TheNameICareAbout" Then ' Do custom handling of this Accessible object handledEvent = True End If End If If Not handledEvent Then If Not accObj Is Nothing Then accObj.SimulateEvent event_OBJECT_FOCUS, apAll End If End If End Sub
The handledEvent variable is a fail safe used to tell Window-Eyes that the event wasn't handled manually (assuming it is False), and that it should instead behave as if the event fired normally (using the Accessible object's SimulateEvent method).
The Accessible object's Prefetch method tells Window-Eyes to gather up all the information regarding the Accessible contained in the event so that it doesn't have to go look up individual pieces of information later on if the event needs to be simulated (as doing so could be very expensive).
When handling the event manually, set handledEvent to True so that the SimulateEvent method is not called (meaning Window-Eyes won't try to act on the event after it has been handled manually).