/// ------------------------------------------------------------------- /// <summary> /// Method that registers the event handler OnEvent() /// </summary> /// ------------------------------------------------------------------- new public virtual void AddEventHandler() { base.AddEventHandler(); Comment("Adding AddAutomationFocusChangedEventHandler"); handler = new AutomationFocusChangedEventHandler(OnEvent); Automation.AddAutomationFocusChangedEventHandler(handler); }
///-------------------------------------------------------------------- /// <summary> /// Register for events of interest. /// </summary> ///-------------------------------------------------------------------- private void RegisterForEvents() { // Focus changes are global; we'll get cached properties for // all elements that receive focus. focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange); Automation.AddAutomationFocusChangedEventHandler(focusHandler); // Register for events from descendants of the root element. // Only the events supported by a control will be registered. invokeHandler = new AutomationEventHandler(OnInvoke); Automation.AddAutomationEventHandler( InvokePattern.InvokedEvent, targetApp, TreeScope.Children, invokeHandler); rangevalueHandler = new AutomationPropertyChangedEventHandler(OnRangeValueChange); Automation.AddAutomationPropertyChangedEventHandler( targetApp, TreeScope.Children, rangevalueHandler, RangeValuePattern.ValueProperty); selectionHandler = new AutomationEventHandler(OnSelectionItemSelected); Automation.AddAutomationEventHandler( SelectionItemPattern.ElementSelectedEvent, targetApp, TreeScope.Descendants, selectionHandler); }
public void SetFocusTest() { AutomationElement [] expectedFocusedElements = new AutomationElement [] { textbox3Element, button2Element }; button2Element.SetFocus(); AutomationFocusChangedEventHandler handler = (s, e) => actualFocusedElements.Add((AutomationElement)s); At.AddAutomationFocusChangedEventHandler(handler); actualFocusedElements.Clear(); textbox3Element.SetFocus(); Thread.Sleep(100); Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement"); button2Element.SetFocus(); Thread.Sleep(100); Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement"); Thread.Sleep(1000); At.RemoveAutomationFocusChangedEventHandler(handler); Assert.AreEqual(expectedFocusedElements.Length, actualFocusedElements.Count, "Event handler count"); for (int i = 0; i < actualFocusedElements.Count; i++) { Assert.AreEqual(expectedFocusedElements [i], actualFocusedElements [i], "Event handler sender #" + i); } }
public void StopDodging() { try { if (!_state.TryingToDodge) { throw new InvalidOperationException("could not stop dodging as the application was not dodging"); } _state.StopDodging(); if (_state.WaitingForUserToAssignDodge) { _state.ToggleWaiting(); } Hook.GlobalEvents().MouseDown -= OnGlobalMouseDown; Automation.RemoveAutomationFocusChangedEventHandler(_focusHandler); _focusHandler = null; } catch (Exception e) { throw e; } }
private void SetupWindowHandling() { #if !DEBUG AutomationFocusChangedEventHandler handler = SoundManager_OnWindowFocusChange; Automation.AddAutomationFocusChangedEventHandler(handler); #endif }
public void UnsubscribeFocusChange() { if (_focusChangedHandler != null) { Automation.RemoveAutomationFocusChangedEventHandler(_focusChangedHandler); _focusChangedHandler = null; } }
// </Snippet1015> // <Snippet102> ///-------------------------------------------------------------------- /// <summary> /// Set up table item event listeners. /// </summary> /// <remarks> /// The event listener is essentially a focus change listener. /// Since this is a global desktop listener, a filter would be required /// to ignore focus change events outside the table. /// </remarks> ///-------------------------------------------------------------------- private void SetTableItemEventListeners() { AutomationFocusChangedEventHandler tableItemFocusChangedListener = new AutomationFocusChangedEventHandler(OnTableItemFocusChange); Automation.AddAutomationFocusChangedEventHandler( tableItemFocusChangedListener); }
// </Snippet1015> // <Snippet102> ///-------------------------------------------------------------------- /// <summary> /// Set up grid item event listeners. /// </summary> /// <param name="targetControl"> /// The grid item container of interest. /// </param> ///-------------------------------------------------------------------- private void SetGridItemEventListeners(AutomationElement targetControl) { AutomationFocusChangedEventHandler gridItemFocusChangedListener = new AutomationFocusChangedEventHandler(OnGridItemFocusChange); Automation.AddAutomationFocusChangedEventHandler( gridItemFocusChangedListener); }
internal static void Add( AutomationFocusChangedEventHandler handlingDelegate) { var e = new AutomationFocusChangedEventHandlerImpl(handlingDelegate: handlingDelegate); var cacheRequest = AutomationElement.DefaultCacheRequest.IUIAutomationCacheRequest; Boundary.UIAutomation(a: () => Automation.AutomationClass.AddFocusChangedEventHandler(cacheRequest: cacheRequest, handler: e)); Add(instance: e); }
/// <summary> /// Called by a client to remove a listener for focus changed events. /// </summary> /// <param name="eventHandler">The handler object that was passed to AddAutomationFocusChangedListener</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void RemoveAutomationFocusChangedEventHandler( AutomationFocusChangedEventHandler eventHandler ) { Misc.ValidateArgumentNonNull(eventHandler, "eventHandler"); // Remove the client-side listener for for this event ClientEventManager.RemoveFocusListener(eventHandler); }
private void OnGlobalMouseDown(object sender, MouseEventArgs e) { var pHandle = WindowFromPoint(e.Location); _state.UpdateProcess(pHandle); _focusHandler = new AutomationFocusChangedEventHandler(OnWindowsFocusChanged); Automation.AddAutomationFocusChangedEventHandler(_focusHandler); }
public override void Start(IEventSink sink) { Validate.ArgumentNotNull(parameter: sink, parameterName: nameof(sink)); Stop(); this._sinkReference = new WeakReference(target: sink); this._sinkReference.Target = sink; this._handlingDelegate = Handler; Automation.AddAutomationFocusChangedEventHandler(eventHandler: this._handlingDelegate); }
private void RegisterForEvents() { // Subscribe to events of interest. // Do this while a CacheRequest is activated, so that the AutomationElement passed // to the event handlers will have cached properties. CacheRequest cacheRequest = new CacheRequest(); cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.ControlTypeProperty); cacheRequest.TreeScope = TreeScope.Element; using (cacheRequest.Activate()) { // Focus changes are global; we'll get cached properties for all elements that receive focus. AutomationFocusChangedEventHandler focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange); Automation.AddAutomationFocusChangedEventHandler(focusHandler); //foreach (AutomationElement element in controlStore) //{ // AutomationPattern[] automationPatterns = element.GetSupportedPatterns(); // foreach (AutomationPattern automationPattern in automationPatterns) // { // switch (automationPattern.ProgrammaticName) // { // case "InvokePatternIdentifiers.Pattern": // AutomationEventHandler invokeHandler = // new AutomationEventHandler(OnInvoke); // Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, element, TreeScope.Element, invokeHandler); // break; // } // } //} //AutomationEventHandler invokeHandler = new AutomationEventHandler(OnInvoke); //Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, // targetApp, TreeScope.Descendants, invokeHandler); foreach (AutomationElement element in controlStore) { if ((bool)element.GetCurrentPropertyValue(AutomationElement.IsInvokePatternAvailableProperty)) { AutomationEventHandler invokeHandler = new AutomationEventHandler(OnInvoke); Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, element, TreeScope.Element, invokeHandler); } if ((bool)element.GetCurrentPropertyValue(AutomationElement.IsRangeValuePatternAvailableProperty)) { //AutomationPropertyChangedEventHandler rangevalueHandler = // new AutomationPropertyChangedEventHandler(OnRangeValueChange); //Automation.AddAutomationPropertyChangedEventHandler( // element, TreeScope.Element, rangevalueHandler, RangeValuePattern. //Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, // element, TreeScope.Element, invokeHandler)); } } } }
public override void Stop() { if (!IsStarted) { return; } Automation.RemoveAutomationFocusChangedEventHandler(eventHandler: this._handlingDelegate); this._handlingDelegate = null; this._sinkReference = null; }
static void Main(string[] args) { InitTimer(); flashWindow = new FlashWindow(); AutomationFocusChangedEventHandler focusHandler = OnFocusChange; Automation.AddAutomationFocusChangedEventHandler(focusHandler); Automation.RemoveAutomationFocusChangedEventHandler(focusHandler); lastIP = GetIP(); Application.Run(); }
public override void Observe() { try { _eventHandler = new AutomationFocusChangedEventHandler(OnEvent); Automation.AddAutomationFocusChangedEventHandler(_eventHandler); } catch (Exception ex) { System.Diagnostics.Debug.Print($"{ex.Message}"); } }
/// <summary> /// Called by a client to add a listener for focus changed events. /// </summary> /// <param name="eventHandler">Delegate to call when a focus change event occurs.</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void AddAutomationFocusChangedEventHandler( AutomationFocusChangedEventHandler eventHandler ) { Misc.ValidateArgumentNonNull(eventHandler, "eventHandler"); // Add a client-side listener for for this event request EventListener l = new EventListener(AutomationElement.AutomationFocusChangedEvent, TreeScope.Subtree | TreeScope.Ancestors, null, CacheRequest.CurrentUiaCacheRequest); ClientEventManager.AddFocusListener(eventHandler, l); }
public static void AddAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler) { Utility.ValidateArgumentNonNull(eventHandler, "eventHandler"); try { FocusEventListener listener = new FocusEventListener(eventHandler); Factory.AddFocusChangedEventHandler(CacheRequest.CurrentNativeCacheRequest, listener); ClientEventList.Add(listener); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
public static void RemoveAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler) { ArgumentCheck.NotNull(eventHandler, "eventHandler"); MUS.FocusChangedEventHandler sourceHandler; lock (focusHandlerMapping) { if (focusHandlerMapping.TryGetValue(eventHandler, out sourceHandler)) { focusHandlerMapping.Remove(eventHandler); foreach (var source in SourceManager.GetAutomationSources()) { source.RemoveAutomationFocusChangedEventHandler(sourceHandler); } } } }
public FocusMontorer() { RegistryKey browserKeys; //on 64bit the browsers are in a different location browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet"); if (browserKeys == null) { browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet"); } browserNames = browserKeys.GetSubKeyNames(); focusHandler = new AutomationFocusChangedEventHandler(OnFocusChangedHandler); Automation.AddAutomationFocusChangedEventHandler(focusHandler); }
public void SubscribeToFocusChange() { Automation.RemoveAllEventHandlers(); _focusHandler = new AutomationFocusChangedEventHandler(OnFocusChanged); //_clickEventHandler = new AutomationEventHandler(OnClickChanged); MinimizeMainWindow(); Automation.AddAutomationFocusChangedEventHandler(_focusHandler); //SubscribeToInvoke(_lastTopLevelWindow); //while (true) //{ // System.Threading.Thread.Yield(); //} //this.WindowState = WindowState.Maximized; }
public void BasicFocusTest() { // TODO: //Currently FocusTest.BasicFocusTest can pass on Windows, but can't on Linux. The failure reason is that: //on Windows, call InvokePattern.Invoke will make corresponding button focused, so we also assert this behavior in the test, //however our implementation will not make the button focused after InvokePattern.Invoke. AutomationElement [] expectedFocusedElements; if (Atspi) { expectedFocusedElements = new AutomationElement [] { btnRunElement, textbox3Element, btnRunElement, button2Element, } } ; else { expectedFocusedElements = new AutomationElement [] { txtCommandElement, textbox3Element, txtCommandElement, button2Element, } }; AutomationFocusChangedEventHandler handler = (s, e) => actualFocusedElements.Add((AutomationElement)s); At.AddAutomationFocusChangedEventHandler(handler); RunCommand("focus textBox3"); Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement"); RunCommand("focus button2"); Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement"); At.RemoveAutomationFocusChangedEventHandler(handler); RunCommand("focus textBox3"); Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement"); At.AddAutomationFocusChangedEventHandler(handler); At.RemoveAllEventHandlers(); RunCommand("focus button2"); Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement"); Assert.AreEqual(expectedFocusedElements.Length, actualFocusedElements.Count, "Event handler count"); for (int i = 0; i < actualFocusedElements.Count; i++) { Assert.AreEqual(expectedFocusedElements [i], actualFocusedElements [i], "Event handler sender #" + i); } }
/// <summary> /// Main method /// </summary> static void Main(string[] args) { #if DEBUG ShowWindow(GetConsoleWindow(), CONSOLE_SHOW); #else ShowWindow(GetConsoleWindow(), CONSOLE_HIDE); #endif hand = new Hand(); hand.closed = false; engagedBodyId = 0; engagedHandType = HandType.NONE; memStream = new MemoryStream(); serializer = new DataContractJsonSerializer(typeof(Hand)); streamReader = new StreamReader(memStream); try { InitializeConnection(); InitilizeKinect(); AutomationFocusChangedEventHandler focusHandler = OnFocusChange; Automation.AddAutomationFocusChangedEventHandler(focusHandler); MessageBox.Show("The program is running in the background, you can now controll nunuStudio´s activities with your hand. \n" + "This program will always be on focus, so it can be annoying when working with other applications. \n" + "To finish it, just close this window. The most easy way is to right click on this window in the taskbar and click close.", "Kinect Hand Motion", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); Automation.RemoveAutomationFocusChangedEventHandler(focusHandler); } catch (Exception) { System.Environment.Exit(1); } Stop(); MessageBox.Show(new Form() { TopMost = true }, "Closed Successfully", "Kinect Hand Motion", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public static void AddAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler) { ArgumentCheck.NotNull(eventHandler, "eventHandler"); MUS.FocusChangedEventHandler sourceHandler; //according to the spec, all static methods in the UIA lib shall be thread safe. lock (focusHandlerMapping) { if (!focusHandlerMapping.TryGetValue(eventHandler, out sourceHandler)) { sourceHandler = (element, objectId, childId) => eventHandler( SourceManager.GetOrCreateAutomationElement(element), new AutomationFocusChangedEventArgs(objectId, childId)); focusHandlerMapping.Add(eventHandler, sourceHandler); } } foreach (var source in SourceManager.GetAutomationSources()) { source.AddAutomationFocusChangedEventHandler(sourceHandler); } }
/// <summary> /// Program entry method /// </summary> private static void Main(string[] args) { //check if the program is already running Process[] _procRunning = Process.GetProcessesByName("AltF4"); if (_procRunning.Length > 1) { Environment.Exit(0); } //Add event handlers AutomationFocusChangedEventHandler focusHandler = OnFocusChanged; Automation.AddAutomationFocusChangedEventHandler(focusHandler); AltF4Handler.Get().OnAltF4 += OnAltF4; //Start program loop Application.Run(); }
public static void RemoveAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler eventHandler) { Utility.ValidateArgumentNonNull(eventHandler, "eventHandler"); try { FocusEventListener listener = (FocusEventListener)ClientEventList.Remove(AutomationElement.AutomationFocusChangedEvent, null, eventHandler); Factory.RemoveFocusChangedEventHandler(listener); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
public Form1() { InitializeComponent(); AutomationFocusChangedEventHandler focusHandler = OnFocusChanged; Automation.AddAutomationFocusChangedEventHandler(focusHandler); flowLayoutActiveAlerts.VerticalScroll.Enabled = true; alertButton.MouseClick += AlertButton_MouseClick; //Add a handler so i can do stuff with clicks //flowLayoutActiveAlerts.scr // Create user and session superUser = new User(); superSession = new Session(superUser); try { lblUserIP.Text = "Your IP: " + MyUtils.GetIPAddress(); } catch (Exception error) { lblUserIP.Text = "Your IP: " + MyUtils.getIP(); } }
private void materialRaisedButton1_Click(object sender, EventArgs e) { if (timer1.Enabled == true) { timer1.Enabled = false; } else { timer1.Enabled = true; } AutomationFocusChangedEventHandler focusHandler = OnFocusChanged; Automation.AddAutomationFocusChangedEventHandler(focusHandler); if (ActivityLog.Count > 0) { foreach (appLog log in ActivityLog) { log.makeTime(); } //richTextBox1.Text = JsonConvert.SerializeObject(ActivityLog, Formatting.Indented); sendShitToFirebase(); } }
/// <summary> /// Called by a client to add a listener for focus changed events. /// </summary> /// <param name="eventHandler">Delegate to call when a focus change event occurs.</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void AddAutomationFocusChangedEventHandler( AutomationFocusChangedEventHandler eventHandler ) { Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" ); // Add a client-side listener for for this event request EventListener l = new EventListener(AutomationElement.AutomationFocusChangedEvent, TreeScope.Subtree | TreeScope.Ancestors, null, CacheRequest.CurrentUiaCacheRequest); ClientEventManager.AddFocusListener(eventHandler, l); }
/// <summary> /// Called by a client to remove a listener for focus changed events. /// </summary> /// <param name="eventHandler">The handler object that was passed to AddAutomationFocusChangedListener</param> /// /// <outside_see conditional="false"> /// This API does not work inside the secure execution environment. /// <exception cref="System.Security.Permissions.SecurityPermission"/> /// </outside_see> public static void RemoveAutomationFocusChangedEventHandler( AutomationFocusChangedEventHandler eventHandler ) { Misc.ValidateArgumentNonNull(eventHandler, "eventHandler" ); //CASRemoval:AutomationPermission.Demand( AutomationPermissionFlag.Read ); // Remove the client-side listener for for this event ClientEventManager.RemoveFocusListener(eventHandler); }
public override void Add(WrappedEventHandler handler, AutomationElementWrapper element) { _handler = (o, e) => handler(element, e); Automation.AddAutomationFocusChangedEventHandler(_handler); }
/// <summary> /// Create an event handler and register it. /// </summary> public void SubscribeToFocusChange() { focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange); Automation.AddAutomationFocusChangedEventHandler(focusHandler); }
public FocusEventListener(AutomationFocusChangedEventHandler handler) : base(AutomationElement.AutomationFocusChangedEvent.Id, null, handler) { Debug.Assert(handler != null); this._focusHandler = handler; }
public static void RemoveAutomationFocusChangedEventHandler (AutomationFocusChangedEventHandler eventHandler) { ArgumentCheck.NotNull (eventHandler, "eventHandler"); MUS.FocusChangedEventHandler sourceHandler; lock (focusHandlerMapping) { if (focusHandlerMapping.TryGetValue (eventHandler, out sourceHandler)) { focusHandlerMapping.Remove (eventHandler); foreach (var source in SourceManager.GetAutomationSources ()) source.RemoveAutomationFocusChangedEventHandler (sourceHandler); } } }
public static void AddAutomationFocusChangedEventHandler (AutomationFocusChangedEventHandler eventHandler) { ArgumentCheck.NotNull (eventHandler, "eventHandler"); MUS.FocusChangedEventHandler sourceHandler; //according to the spec, all static methods in the UIA lib shall be thread safe. lock (focusHandlerMapping) { if (!focusHandlerMapping.TryGetValue (eventHandler, out sourceHandler)) { sourceHandler = (element, objectId, childId) => eventHandler ( SourceManager.GetOrCreateAutomationElement (element), new AutomationFocusChangedEventArgs (objectId, childId)); focusHandlerMapping.Add (eventHandler, sourceHandler); } } foreach (var source in SourceManager.GetAutomationSources ()) source.AddAutomationFocusChangedEventHandler (sourceHandler); }
/// ------------------------------------------------------------------- /// <summary> /// Call SetFocus() and verify the it does get focus by verifying /// that the event does occur. Even if you are not testing for events, /// we use the event handler to determine that the element got /// the focus. /// </summary> /// ------------------------------------------------------------------- internal void TSC_SetFocusVerifyWithEvent(AutomationElement element, CheckType checkType) { AutomationFocusChangedEventHandler handler = null; bool fired = false; try { m_FocusEvents = new ArrayList(); Comment("Adding AutomationFocusChangedEventHandler"); handler = new AutomationFocusChangedEventHandler(OnFocusChanged); Automation.AddAutomationFocusChangedEventHandler(handler); Comment("Calling SetFocus() on " + Library.GetUISpyLook(element)); // Set the notifier m_NotifiedEvent.Reset(); element.SetFocus(); Comment("Wait 1 second for event to happen"); m_NotifiedEvent.WaitOne(1000, false); Comment("Stopped waiting for event to happen"); Comment("Calling RemoveAutomationFocusChangedEventHandler()"); Automation.RemoveAutomationFocusChangedEventHandler(handler); Comment("Called RemoveAutomationFocusChangedEventHandler()"); try { // Lock this so we don't get anymore events fired. #pragma warning suppress 6517 lock (this) { foreach (AutomationElement tempElement in m_FocusEvents) { AutomationElement el = tempElement; Comment("History of events fired: " + el.Current.Name); // Check to see if any of the elements are the element, or one of the children while (!Automation.Compare(el, AutomationElement.RootElement) && !Automation.Compare(el, element)) el = TreeWalker.ControlViewWalker.GetParent(el); if (Automation.Compare(el, element)) { fired = true; break; } } } } finally { } } finally { } if (!fired) ThrowMe(CheckType.Verification, "Element or one of it's children did not fire the FocusChange event"); m_TestStep++; }
public static IDisposable ToFocusChangedEvent(AutomationFocusChangedEventHandler handler) { Automation.AddAutomationFocusChangedEventHandler(handler); return(Disposable.Create(() => Automation.RemoveAutomationFocusChangedEventHandler(handler))); }
/// <summary> /// Subscribe to UI Automation events. /// </summary> /// <remarks> /// Do not call from the UI thread. /// </remarks> private void StartListening() { _focusHandler = OnFocusChanged; Automation.AddAutomationFocusChangedEventHandler(_focusHandler); }
protected internal void SubscribeToEvents(HasControlInputCmdletBase cmdlet, AutomationElement inputObject, AutomationEvent eventType, AutomationProperty prop) { AutomationEventHandler uiaEventHandler; AutomationPropertyChangedEventHandler uiaPropertyChangedEventHandler; StructureChangedEventHandler uiaStructureChangedEventHandler; AutomationFocusChangedEventHandler uiaFocusChangedEventHandler; // 20130109 if (null == CurrentData.Events) { CurrentData.InitializeEventCollection(); } try { CacheRequest cacheRequest = new CacheRequest(); cacheRequest.AutomationElementMode = AutomationElementMode.Full; //.None; cacheRequest.TreeFilter = Automation.RawViewCondition; cacheRequest.Add(AutomationElement.NameProperty); cacheRequest.Add(AutomationElement.AutomationIdProperty); cacheRequest.Add(AutomationElement.ClassNameProperty); cacheRequest.Add(AutomationElement.ControlTypeProperty); //cacheRequest.Add(AutomationElement.ProcessIdProperty); // cache patterns? // cacheRequest.Activate(); cacheRequest.Push(); switch (eventType.ProgrammaticName) { case "InvokePatternIdentifiers.InvokedEvent": this.WriteVerbose(cmdlet, "subscribing to the InvokedEvent handler"); Automation.AddAutomationEventHandler( InvokePattern.InvokedEvent, inputObject, TreeScope.Element, // TreeScope.Subtree, // TreeScope.Element, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "TextPatternIdentifiers.TextChangedEvent": this.WriteVerbose(cmdlet, "subscribing to the TextChangedEvent handler"); Automation.AddAutomationEventHandler( TextPattern.TextChangedEvent, inputObject, TreeScope.Element, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "TextPatternIdentifiers.TextSelectionChangedEvent": this.WriteVerbose(cmdlet, "subscribing to the TextSelectionChangedEvent handler"); Automation.AddAutomationEventHandler( TextPattern.TextSelectionChangedEvent, inputObject, TreeScope.Element, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "WindowPatternIdentifiers.WindowOpenedProperty": this.WriteVerbose(cmdlet, "subscribing to the WindowOpenedEvent handler"); Automation.AddAutomationEventHandler( WindowPattern.WindowOpenedEvent, inputObject, TreeScope.Subtree, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.AutomationPropertyChangedEvent": if (prop != null) { this.WriteVerbose(cmdlet, "subscribing to the AutomationPropertyChangedEvent handler"); Automation.AddAutomationPropertyChangedEventHandler( inputObject, TreeScope.Subtree, uiaPropertyChangedEventHandler = // new AutomationPropertyChangedEventHandler(OnUIAutomationPropertyChangedEvent), //new AutomationPropertyChangedEventHandler(handler), //new AutomationPropertyChangedEventHandler(((EventCmdletBase)cmdlet).AutomationPropertyChangedEventHandler), new AutomationPropertyChangedEventHandler(cmdlet.AutomationPropertyChangedEventHandler), prop); UIAHelper.WriteEventToCollection(cmdlet, uiaPropertyChangedEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaPropertyChangedEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaPropertyChangedEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } } break; case "AutomationElementIdentifiers.StructureChangedEvent": this.WriteVerbose(cmdlet, "subscribing to the StructureChangedEvent handler"); Automation.AddStructureChangedEventHandler( inputObject, TreeScope.Subtree, uiaStructureChangedEventHandler = // new StructureChangedEventHandler(OnUIStructureChangedEvent)); //new StructureChangedEventHandler(handler)); //new StructureChangedEventHandler(((EventCmdletBase)cmdlet).StructureChangedEventHandler)); new StructureChangedEventHandler(cmdlet.StructureChangedEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaStructureChangedEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaStructureChangedEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaStructureChangedEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "WindowPatternIdentifiers.WindowClosedProperty": this.WriteVerbose(cmdlet, "subscribing to the WindowClosedEvent handler"); Automation.AddAutomationEventHandler( WindowPattern.WindowClosedEvent, inputObject, TreeScope.Subtree, // uiaEventHandler = new AutomationEventHandler(OnUIAutomationEvent)); //uiaEventHandler = new AutomationEventHandler(handler)); //uiaEventHandler = new AutomationEventHandler(((EventCmdletBase)cmdlet).AutomationEventHandler)); uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.MenuClosedEvent": this.WriteVerbose(cmdlet, "subscribing to the MenuClosedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.MenuClosedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.MenuOpenedEvent": this.WriteVerbose(cmdlet, "subscribing to the MenuOpenedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.MenuOpenedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.ToolTipClosedEvent": this.WriteVerbose(cmdlet, "subscribing to the ToolTipClosedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.ToolTipClosedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.ToolTipOpenedEvent": this.WriteVerbose(cmdlet, "subscribing to the ToolTipOpenedEvent handler"); Automation.AddAutomationEventHandler( AutomationElement.ToolTipOpenedEvent, inputObject, TreeScope.Subtree, uiaEventHandler = new AutomationEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; case "AutomationElementIdentifiers.AutomationFocusChangedEvent": WriteVerbose(cmdlet, "subscribing to the AutomationFocusChangedEvent handler"); Automation.AddAutomationFocusChangedEventHandler( //AutomationElement.AutomationFocusChangedEvent, //inputObject, //System.Windows.Automation.AutomationElement.RootElement, //TreeScope.Subtree, uiaFocusChangedEventHandler = new AutomationFocusChangedEventHandler(cmdlet.AutomationEventHandler)); UIAHelper.WriteEventToCollection(cmdlet, uiaFocusChangedEventHandler); // 20130327 //this.WriteObject(cmdlet, uiaFocusChangedEventHandler); if (cmdlet.PassThru) { cmdlet.WriteObject(cmdlet, uiaFocusChangedEventHandler); } else { cmdlet.WriteObject(cmdlet, true); } break; default: this.WriteVerbose(cmdlet, "the following event has not been subscribed to: " + eventType.ProgrammaticName); break; } this.WriteVerbose(cmdlet, "on the object " + inputObject.Current.Name); cacheRequest.Pop(); } catch (Exception e) { // try { // ErrorRecord err = new ErrorRecord( // e, // "RegisteringEvent", // ErrorCategory.OperationStopped, // inputObject); // err.ErrorDetails = // new ErrorDetails("Unable to register event handler " + // // handler.ToString()); // eventType.ProgrammaticName + // " for " + // inputObject.Current.Name); // // this.OnSuccessAction.ToString()); // WriteError(this, err, false); // } // catch { // ErrorRecord err = new ErrorRecord( // e, // "RegisteringEvent", // ErrorCategory.OperationStopped, // inputObject); // err.ErrorDetails = // new ErrorDetails("Unable to register event handler " + // eventType.ProgrammaticName);; // WriteError(this, err, false); // } WriteVerbose(cmdlet, "Unable to register event handler " + eventType.ProgrammaticName + " for " + inputObject.Current.Name); WriteVerbose(cmdlet, e.Message); } }
public void SubscribeToFocusChange() { _focusChangedHandler = new AutomationFocusChangedEventHandler(OnFocusChange); Automation.AddAutomationFocusChangedEventHandler(_focusChangedHandler); }