There may be times when you want to tell Window-Eyes to ignore specific MSAA events so that you can handle them yourself. For instance, you may want to speak something custom when a particular control gets the focus. To do this however, you'll need to keep Window-Eyes from seeing any MSAA focus events for a particular window or process, and create a handler of your own which will see all of these MSAA focus events and decide if it's one you want to handle, or if you want to allow Window-Eyes to see (and handle) it after all.
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)
(note that it's necessary to save the result from the call to MSAAEventSource.BlockEvent() in a global variable; if this isn't done, then the blocked event will become unblocked immediately).
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
(Note: because a property of msaaEventSource needs to be modified, it's necessary to make a copy of the root level object into a variable, before doing so; just as with the results of the blockEvent method, this variable must be global in scope or both the filtering and the hooking will fail when it goes out of scope).
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 handler for the onObjectFocus event might look something like:
Sub OnObjectFocus(accObj)
handledEvent = False
If Not accObj Is Nothing Then
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 ' this allows Window-Eyes to see this event after all
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).
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).


