public void AutomationFocusChangedEventArgsTest() { var args = new AutomationFocusChangedEventArgs(0, 0); Assert.AreEqual(AutomationElementIdentifiers.AutomationFocusChangedEvent, args.EventId); }
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { var element = sender as AutomationElement; if (element == null) { return; } using (var process = Process.GetProcessById(element.Current.ProcessId)) { if (process.ProcessName != "notepad") { return; } } if (element.Current.ControlType.ProgrammaticName != "ControlType.MenuItem") { return; } Log?.Invoke(element.Current.Name); Speech.SpeakAsyncCancelAll(); Speech.SpeakAsync(element.Current.Name); }
///string menuId; private void OnMenuFocusEvent(object src, AutomationFocusChangedEventArgs e) { var element = src as AutomationElement; try { if (element.Current.ControlType.In(ControlType.ComboBox, ControlType.MenuItem)) { // System.Diagnostics.Debug.WriteLine(element.Current.Name + "/" + element.Current.AutomationId); if (element.FindFirst(TreeScope.Children, System.Windows.Automation.Condition.TrueCondition) != null)//(element.Current.Name.EndsWith("DropDown") && element.Current.Name.Length > "DropDown".Length) { menuTop = element.Current.Name; } else { focused = element.Current.Name; } } else { menuTop = ""; focused = ""; } } catch (ElementNotAvailableException) { System.Diagnostics.Debug.WriteLine("ElementNotAvailableException caused"); } }
private static void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { AutomationElement elementFocused = sender as AutomationElement; if (elementFocused == null) { return; } try { AutomationElement topLevelWindow = GetParentWindow(elementFocused); if (topLevelWindow == null) { return; } if (topLevelWindow != _lastWindow) { _lastWindow = topLevelWindow; Console.WriteLine("Focus moved to window: {0}", topLevelWindow.Current.Name); } else { Console.WriteLine("Focused element: Type: '{0}', Name:'{1}'", elementFocused.Current.LocalizedControlType, elementFocused.Current.Name); } } catch (ElementNotAvailableException) { } }
private void SoundManager_OnWindowFocusChange(object source, AutomationFocusChangedEventArgs e) { var focusedHandle = new IntPtr(AutomationElement.FocusedElement.Current.NativeWindowHandle); var mainWindowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; if (focusedHandle == mainWindowHandle) { foreach (var sound in sounds) { if (sound.IsPaused()) { sound.Play(); } } } else { foreach (var sound in sounds) { if (sound.IsPlaying()) { sound.Pause(); } } } }
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { if (FocusChanged != null) { FocusChanged(sender, e); } }
/// <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; } }
private void OnFocusChangedHandler(object sender, AutomationFocusChangedEventArgs e) { AutomationElement element = sender as AutomationElement; if (element != null) { try { //string name = element.Current.Name; //string id = element.Current.AutomationId; int processId = element.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { if (isBrowserFocus(process.ProcessName)) { if (FocusChanged != null) { FocusChanged(sender, e); } } //Console.WriteLine(" Name: {0}, Id: {1}, Process: {2}", name, id, process.ProcessName); } } catch //ElementNotAvailableException { } } }
/// <summary> /// Handles focus-changed events. If the element that received focus is /// in a different top-level window, announces that. If not, just /// announces which element received focus. /// </summary> /// <param name="src">Object that raised the event.</param> /// <param name="e">Event arguments.</param> private void OnFocusChanged(object src, AutomationFocusChangedEventArgs e) { try { var elementFocused = src as AutomationElement; var topLevelWindow = GetTopLevelWindow(elementFocused); if (topLevelWindow == null) { return; } // If top-level window has changed, announce it. if (topLevelWindow != _lastTopLevelWindow) { _lastTopLevelWindow = topLevelWindow; Console.WriteLine("Focus moved to top-level window:"); Console.WriteLine(" " + topLevelWindow.Current.Name); Console.WriteLine(); } else { // Announce focused element. Console.WriteLine("Focused element: "); Console.WriteLine(" Type: " + elementFocused.Current.LocalizedControlType); Console.WriteLine(" Name: " + elementFocused.Current.Name); Console.WriteLine(); } } catch (ElementNotAvailableException) { } }
void UIAutomationClient.IUIAutomationFocusChangedEventHandler.HandleFocusChangedEvent( UIAutomationClient.IUIAutomationElement sender) { // Can't set the arguments -- they come from a WinEvent handler. AutomationFocusChangedEventArgs args = new AutomationFocusChangedEventArgs(0, 0); _focusHandler(AutomationElement.Wrap(sender), args); }
private async void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { _focusSource?.Cancel(); var source = new CancellationTokenSource(); _focusSource = source; await Task.Run(async() => { try { if (source.IsCancellationRequested) { return; } Debug.WriteLine("focus changed"); var focusedElement = sender as AutomationElement; if (focusedElement == null) { return; } var window = GetTopLevelWindow(focusedElement, source); if (source.IsCancellationRequested) { return; } if (window == null) { Debug.WriteLine("Null window"); return; } if (_focusedWindow == window) { Debug.WriteLine("Same window"); //return; } try { if (_focusedWindow != null) { Automation.RemoveStructureChangedEventHandler(_focusedWindow, OnStructureChanged); } } catch (ArgumentException ex) { } _focusedWindow = window; FocusedWindowChanged?.Invoke(this, _focusedWindow); await Update(); Automation.AddStructureChangedEventHandler(_focusedWindow, TreeScope.Subtree, OnStructureChanged); } catch (COMException) { } }); }
private void OnFocusChange(object src, AutomationFocusChangedEventArgs e) { // TODO Add event handling code. // The arguments tell you which elements have lost and received focus. txtOutput.Text += "\r\nUI Automation Focus Changed: " + e.ObjectId; txtOutput.Text += "\r\nObjectId=" + e.ObjectId; txtOutput.Text += "\r\ne=" + e.ToString(); txtOutput.Text += "\r\nsrc=" + src.ToString(); }
private void FocusChangedHandler(object sender, AutomationFocusChangedEventArgs e) { var handler = FocusChanged; if (handler != null) { handler(sender, e); } }
public static void OnFocusChange(object source, AutomationFocusChangedEventArgs e) { var focusedHandle = new IntPtr(AutomationElement.FocusedElement.Current.NativeWindowHandle); var myConsoleHandle = Process.GetCurrentProcess().MainWindowHandle; if (focusedHandle == myConsoleHandle) { flashWindow.StopFlash(); } }
/// <summary> /// Always put this application with focus, to be able to receive pointer input from kinect /// </summary> /// <param name="source">object sending the event</param> /// <param name="e">event arguments</param> private static void OnFocusChange(object source, AutomationFocusChangedEventArgs e) { var focusedHandle = new IntPtr(AutomationElement.FocusedElement.Current.NativeWindowHandle); var myConsoleHandle = GetConsoleWindow(); if (focusedHandle != myConsoleHandle) { SetForegroundWindow(myConsoleHandle); } }
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { AutomationElement focusedElement = sender as AutomationElement; try { this.BeginInvoke(new ChangeRichTextBoxDelegate(ChangeRichTextBox), focusedElement); } catch { } }
private static void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { AutomationElement focusedElement = sender as AutomationElement; if (focusedElement != null) { int processId = focusedElement.Current.ProcessId; procFocus = Process.GetProcessById(processId); } }
//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods // The method that gets called from CallbackQueue's thread. Uses Post to invoke the callback on the proper thread. internal static void InvokeClientHandler(Delegate clientCallback, AutomationElement srcEl, AutomationEventArgs args) { try { if (args is AutomationPropertyChangedEventArgs) { ((AutomationPropertyChangedEventHandler)clientCallback)(srcEl, (AutomationPropertyChangedEventArgs)args); } else if (args is StructureChangedEventArgs) { ((StructureChangedEventHandler)clientCallback)(srcEl, (StructureChangedEventArgs)args); } else if (args is InternalAutomationFocusChangedEventArgs) { AutomationFocusChangedEventArgs realArgs = ((InternalAutomationFocusChangedEventArgs)args)._args; // For focus events, check that the event is actually more recent than the last one (see note at top of file). // Since the timestamps can wrap around, subtract and measure the delta instead of just comparing them. // Any events that appear to have taken place within the 5 seconds before the last event we got will be ignored. // (Because of wraparound, certain before- and after- time spans share the same deltas; 5000ms before has the // same value as MAXUINT-5000ms after. Since we're just trying to filter out very recent event race conditions, // confine this test to a small window, just the most recent 5 seconds. That means you'd have to wait a *very* // long time without any focus changes before getting a false positive here.) uint eventTime = ((InternalAutomationFocusChangedEventArgs)args)._eventTime; if (_lastFocusEventTime != 0) { uint delta = _lastFocusEventTime - eventTime; // Exclude events that happend before the last one, but do allow any that happened "at the same time", // (delta==0) since they likely actually happened after, but within the resolution of the event timer. if (delta < 5000 && delta != 0) { return; } } _lastFocusEventTime = eventTime; ((AutomationFocusChangedEventHandler)clientCallback)(srcEl, realArgs); } else { ((AutomationEventHandler)clientCallback)(srcEl, args); } } catch (Exception e) { if (Misc.IsCriticalException(e)) { throw; } // Since we can't predict what exceptions an outside client might throw intentionally ignore all } }
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { AutomationElement focusedElement = sender as AutomationElement; if (focusedElement != null) { int processId = focusedElement.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { Debug.WriteLine(process.ProcessName); } } }
public void OnFocusChange(object src, AutomationFocusChangedEventArgs e) { var sourceElement = src as AutomationElement; var allElements = finder.FindAllElements(new WindowElement(sourceElement.Current.AutomationId, sourceElement.Current.Name)); foreach (WindowElement element in allElements) { if (element.Id == sourceElement.Current.AutomationId && element.Name == sourceElement.Current.Name && sourceElement.Current.HasKeyboardFocus) { speaker.Speak(sourceElement.Current.Name); } } }
public static void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { AutomationElement focusedElement = sender as AutomationElement; if (focusedElement != null) { int processId = focusedElement.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { Console.WriteLine(process.ProcessName); proc = process.ProcessName; } } }
private void FocusChangedEvent_OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { bool flag = sender == null; if (!flag) { bool flag2 = e.EventId == AutomationElementIdentifiers.AutomationFocusChangedEvent; if (flag2) { this.CurrentElement = (AutomationElement)sender; this.DrawRectangle(); this.ShowProperty(); } } }
private void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args) { WriteOut("----| Focus changed!\r\n"); AutomationElement element = src as AutomationElement; if (element != null) { int processId = element.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { WriteOut(line.ToString("000") + "| Process: " + process.ProcessName + "r\n"); line++; } } }
private static void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args) { Console.WriteLine("Focus changed!"); AutomationElement element = src as AutomationElement; if (element != null) { string name = element.Current.Name; string id = element.Current.AutomationId; int processId = element.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { Console.WriteLine(" Name: {0}, Id: {1}, Process: {2}", name, id, process.ProcessName); } } }
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { try { AutomationElement elementFocused = sender as AutomationElement; if (IsInvalidAutomationElement(elementFocused)) { return; } AutomationElement newTopLevelWindow = GetTopLevelWindow(elementFocused); if (IsInvalidAutomationElement(newTopLevelWindow)) { return; } if (newTopLevelWindow != lastTopLevelWindow) { if (IsExplorerWindow(lastTopLevelWindow)) { RemoveSelectionEvenhandler(lastTopLevelWindow); } if (IsExplorerWindow(newTopLevelWindow)) { Debug.WriteLine("Focus moved to new top-level explorer window " + newTopLevelWindow.Current.Name); AddSelectionEvenhandler(newTopLevelWindow); ExplorerWindowGotFocus?.Invoke(this, new IntPtr(newTopLevelWindow.Current.NativeWindowHandle)); } else { Debug.WriteLine("Focus moved to new top-level non-explorer window " + newTopLevelWindow.Current.Name); } lastTopLevelWindow = newTopLevelWindow; } } catch (ElementNotAvailableException ex) { Debug.WriteLine("SelectionMonitor: Fail OnFocusChanged " + ex.ToString()); } }
private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e) { if (ActivityLog.Count > 0) { foreach (appLog log in ActivityLog) { log.StopStopwatch(); } } AutomationElement focusedElement = sender as AutomationElement; if (focusedElement != null) { int processId = focusedElement.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { if (ActivityLog.Count > 0) { bool goingFurther = true; foreach (appLog log in ActivityLog.ToArray()) { if (log.name == process.ProcessName) { log.StartStopwatch(); goingFurther = false; } } if (goingFurther) { AuthLink.RefreshUserDetails(); appLog newAppLog = new appLog(process.ProcessName, AuthLink.User.LocalId); ActivityLog.Add(newAppLog); } } else { AuthLink.RefreshUserDetails(); appLog newAppLog = new appLog(process.ProcessName, AuthLink.User.LocalId); ActivityLog.Add(newAppLog); } } } }
/// <summary> /// Handles focus-changed events. If the element that received focus is /// in a different top-level window, announces that. If not, just /// announces which element received focus. /// </summary> /// <param name="src">Object that raised the event.</param> /// <param name="e">Event arguments.</param> private void OnFocusChanged(object src, AutomationFocusChangedEventArgs e) { try { AutomationElement elementFocused = src as AutomationElement; AutomationElement topLevelWindow = GetTopLevelWindow(elementFocused); if (topLevelWindow == null) { return; } // If top-level window has changed, announce it. if (topLevelWindow != lastTopLevelWindow) { lastTopLevelWindow = topLevelWindow; Console.WriteLine("Focus moved to top-level window:"); Console.WriteLine(" " + topLevelWindow.Current.Name); Console.WriteLine(); } else { // Announce focused element. Console.WriteLine("Focused element: "); Console.WriteLine(" Type: " + elementFocused.Current.LocalizedControlType); Console.WriteLine(" Name: " + elementFocused.Current.Name); Console.WriteLine(); if (topLevelWindow.Current.Name.Contains("Mozilla Firefox") && elementFocused.Current.ControlType == ControlType.Document) { var c = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Hyperlink); var links = elementFocused.FindAll(TreeScope.Descendants, c); Console.WriteLine("Found {0} Links", links.Count); foreach (AutomationElement link in links) { Console.WriteLine("Link: {0}", link.Current.Name); } } } } catch (ElementNotAvailableException) { return; } }
public void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args) { // System.Windows.MessageBox.Show("Focus changed!"); AutomationElement element = src as AutomationElement; if (element != null) { string name = element.Current.Name; string id = element.Current.AutomationId; int processId = element.Current.ProcessId; using (Process process = Process.GetProcessById(processId)) { // Console.WriteLine(" Name: {0}, Id: {1}, Process: {2}", name, id, process.ProcessName); System.Windows.MessageBox.Show(name.ToString()); } } }
private void FocusChangedHandler(object src, AutomationFocusChangedEventArgs args) { var element = src as AutomationElement; try { if (element != null && _focusedProcessId != element.Current.ProcessId) { var previousFocusedProcessId = _focusedProcessId; _focusedProcessId = element.Current.ProcessId; OnApplicationFocusChanged(previousFocusedProcessId, _focusedProcessId); } } catch (Exception ex) { Debug.WriteLine($"{ex.GetType().Name}, {ex.Message}"); } }
private void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args) { if (!mnuSetEveToBackground.Checked) { return; } AutomationElement element = src as AutomationElement; var processes = Process.GetProcesses().Where(p => p.ProcessName.ToLower() == processname.ToLower()).ToList(); if (processes.Count > 0) { Process process = processes[0]; int id = process.Id; SetWindowPos(process.MainWindowHandle, HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.DoNotReposition | SetWindowPosFlags.IgnoreMove | SetWindowPosFlags.DoNotActivate | SetWindowPosFlags.IgnoreResize); } }