/// <summary> /// Handle the event. /// </summary> /// <param name="src">Object that raised the event.</param> /// <param name="e">Event arguments.</param> private void OnFocusChange(object src, AutomationFocusChangedEventArgs e) { DateTime invokeTime = DateTime.Now; Feedback("Focus changed."); AutomationElement focusedElement = src as AutomationElement; AutomationElement topLevelWindow = GetTopLevelWindow(focusedElement); if (topLevelWindow != targetApp) { return; } Feedback(focusedElement.Current.Name); ElementStore focusChange = new ElementStore(); try { focusChange.AutomationID = focusedElement.Current.AutomationId; focusChange.ClassName = focusedElement.Current.ClassName; focusChange.ControlType = focusedElement.Current.ControlType.ProgrammaticName; focusChange.EventID = e.EventId.ProgrammaticName; focusChange.SupportedPatterns = focusedElement.GetSupportedPatterns(); focusChange.EventTime = invokeTime; elementQueue.Enqueue(focusChange); } catch (NullReferenceException) { return; } }
/// <summary> /// Handle invoke events of interest. /// </summary> /// <param name="src">Object that raised the event.</param> /// <param name="e">Event arguments.</param> /// <remarks> /// Some controls that have not implemented UI Automation correctly /// may fire spurious events. For example, a WinForms button will /// fire an InvokedEvent on a mouse-down and then another series of /// InvokedEvents on the subsequent mouse-up.</remarks> private void OnInvoke(object src, AutomationEventArgs e) { DateTime invokeTime = DateTime.Now; Feedback("Invoke event."); AutomationElement invokedElement = src as AutomationElement; Feedback(invokedElement.Current.Name); ElementStore invokeEvent = new ElementStore(); try { invokeEvent.AutomationID = invokedElement.Current.AutomationId; invokeEvent.ClassName = invokedElement.Current.ClassName; invokeEvent.ControlType = invokedElement.Current.ControlType.ProgrammaticName; invokeEvent.EventID = e.EventId.ProgrammaticName; invokeEvent.SupportedPatterns = invokedElement.GetSupportedPatterns(); invokeEvent.EventTime = invokeTime; elementQueue.Enqueue(invokeEvent); } catch (NullReferenceException) { return; } }
private void OnStructureChange(object src, StructureChangedEventArgs e) { AutomationElement source = src as AutomationElement; ElementStore structureChange = new ElementStore(); structureChange.AutomationID = source.Current.AutomationId; structureChange.EventID = e.EventId.ProgrammaticName; elementStore.Enqueue(structureChange); }