Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        internal static void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e)
        {
            AutomationElement ae = sender as AutomationElement;

            if (ae == null)
            {
                return;
            }
            bool hasFocus = false;

            try {
                hasFocus = ae.Current.HasKeyboardFocus;
                if ((!hasFocus) && ae == focusedElement)
                {
                    focusedElement = null;
                }
                else
                {
                    focusedElement = ae;
                }
            } catch (ElementNotAvailableException) {
                focusedElement = null;
            } catch (Exception ex) {
                Log.Error("[OnFocusChanged] Unknown Error: {0}", ex);
                focusedElement = null;
            }
        }
Esempio n. 3
0
        private void HandleFocusChangedEvent(object sender, UIA.AutomationFocusChangedEventArgs automationFocusChangedEventArgs)
        {
            var basicAutomationElement = new UIA2BasicAutomationElement((UIA2Automation)Automation, (UIA.AutomationElement)sender);
            var senderElement          = new AutomationElement(basicAutomationElement);

            HandleFocusChangedEvent(senderElement);
        }
        private void HandleFocusChangedEvent(object sender, UIA.AutomationFocusChangedEventArgs automationFocusChangedEventArgs)
        {
            var frameworkElement = new UIA2FrameworkAutomationElement((UIA2Automation)Automation, (UIA.AutomationElement)sender);
            var senderElement    = new AutomationElement(frameworkElement);

            HandleFocusChangedEvent(senderElement);
        }
Esempio n. 5
0
        void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e)
        {
            AutomationElement element = sender as AutomationElement;
            if (element == null) { return; }

            int processId = element.Current.ProcessId;
            using (Process process = Process.GetProcessById(processId))
            {
                currentProcess = process.ProcessName;
                //Debug.WriteLine(String.Format("Current process: {0}",currentProcess));
            }
        }
Esempio n. 6
0
        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++;
                }
            }
        }
Esempio n. 7
0
		internal static void OnFocusChanged (object sender, AutomationFocusChangedEventArgs e)
		{
			AutomationElement ae = sender as AutomationElement;
			if (ae == null)
				return;
			bool hasFocus = false;
			try {
				hasFocus = ae.Current.HasKeyboardFocus;
				if ((!hasFocus) && ae == focusedElement)
					focusedElement = null;
				else
					focusedElement = ae;
			} catch (ElementNotAvailableException) {
				focusedElement = null;
			} catch (Exception ex) {
				Log.Error ("[OnFocusChanged] Unknown Error: {0}", ex);
				focusedElement = null;
			}
		}
Esempio n. 8
0
        private static void ListenToEditElement(object sender, AutomationFocusChangedEventArgs e)
        {
            var element = (AutomationElement) sender;

            if (element.Current.ControlType == ControlType.Edit && DiffersFromLastElement(element))
            {
                if (HandlerExists())
                {
                    RemoveHandler();
                }

                Automation.AddAutomationPropertyChangedEventHandler(
                    element,
                    TreeScope.Element,
                    LogElementText,
                    AutomationElementIdentifiers.NameProperty,
                    ValuePattern.ValueProperty
                );

                _lastElement = element;
            }
        }
Esempio n. 9
0
        private static void OnFocusChangedHandler(object src, AutomationFocusChangedEventArgs args)
        {
            AutomationElement element = src as AutomationElement;
            if (element != null)
            {
                string id = element.Current.AutomationId;
                int processId = element.Current.ProcessId;

                using (Process process = Process.GetProcessById(processId))
                {
                    _s.record(process.ProcessName);
                }
            }
        }
        private void OnFocusChanged(object sender, AutomationFocusChangedEventArgs e)
        {
            AutomationElement senderElement = sender as AutomationElement;
            Debug.WriteLine(IsVisible);
            Debug.WriteLine(senderElement.Current.AutomationId);
            Debug.WriteLine(senderElement.Current.ClassName);
            Debug.WriteLine(senderElement.Current.ControlType);
            Debug.WriteLine(senderElement.Current.FrameworkId);
            Debug.WriteLine(senderElement.Current.Name);
            Debug.WriteLine(senderElement.Current.ProcessId);
            Debug.WriteLine("\r\n");

            var element = sender as AutomationElement;
            ControlType controlTypeId = element.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty) as ControlType;
            //Console.WriteLine(controlTypeId.LocalizedControlType);
            if ((controlTypeId.LocalizedControlType == "combo box" || controlTypeId.LocalizedControlType == "edit") && (senderElement.Current.ProcessId != Process.GetCurrentProcess().Id))
            {

                if (this.Visibility == Visibility.Visible && (senderElement.Current.ProcessId != Process.GetCurrentProcess().Id))
                    Dispatcher.Invoke(() =>
                    {
                        Visibility = Visibility.Collapsed;
                    });

                Rect editBoxRect = (Rect)element.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

                this.Dispatcher.Invoke((Action)(() =>
                {
                    Height = editBoxRect.Height;
                    Width = editBoxRect.Width;
                    Left = editBoxRect.Left;
                    Top = editBoxRect.Top;

                    Visibility = Visibility.Visible;
                }));

                /*
                  canvas.Width = (int)editBoxRect.Width;
                  canvas.Height = (int)editBoxRect.Height;
                  canvas.Location = new System.Drawing.Point(Convert.ToInt32(editBoxRect.X), Convert.ToInt32(editBoxRect.Y));
                  canvas.Show();
                  */

                object patternObj;
                if (element.TryGetCurrentPattern(ValuePattern.Pattern, out patternObj))
                {
                    var valuePattern = patternObj as ValuePattern;
                    //Console.WriteLine(valuePattern.Current.Value);

                    //  valuePattern.SetValue("sucker");

                }
                else if (element.TryGetCurrentPattern(TextPattern.Pattern, out patternObj))
                {
                    var textPattern = patternObj as TextPattern;
                    Console.WriteLine(textPattern.DocumentRange.GetText(-1).TrimEnd('\r'));
                }
                else
                {
                    Console.WriteLine(element.Current.Name);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        ///     Responds to focus changes. Starts the timer so that the highlight
        ///     will be updated, or updates the highlight immediately if the timer
        ///     interval is set to 0.
        /// </summary>
        /// <param name="src">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        private void OnFocusChanged(object src, AutomationFocusChangedEventArgs e)
        {
            _focusedElement = src as AutomationElement;
            _focusedRect = _focusedElement.Current.BoundingRectangle;

#if DEBUG
            Console.WriteLine("Focus moved to: " + _focusedElement.Current.Name);
#endif

            if (_useTimer)
            {
                _eventTimer.Interval = _timerInterval;
                _eventTimer.Start();
            }
            else
            {
                UpdateHighlight();
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
 private void OnAutomationFocusChanged(object s, AutomationFocusChangedEventArgs e)
 {
     MessageBox.Show($"e.ObjectId: {e.ObjectId}"
              + L.f + $"e.ChildId: {e.ChildId}"
              + L.f + $"e.EventId: {e.EventId}");
 }
Esempio n. 14
0
 /// -------------------------------------------------------------------
 /// <summary>
 /// Method registered by AddEventHandler() as an event handler
 /// </summary>
 /// -------------------------------------------------------------------
 public virtual void OnEvent(object element, AutomationFocusChangedEventArgs argument)
 {
     base.OnEvent(((AutomationElement)(element)), argument);
 }
Esempio n. 15
0
        /// <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)
            {
            }
        }
Esempio n. 16
0
        /// <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;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// this method will handle the AutomationFocusChanged event
        /// </summary>
        private void OnAutomationFocusChanged(object src, AutomationFocusChangedEventArgs e)
        {
            Debug.WriteLine("OnAutomationFocusChanged ...");

            OnAutomationFocusChanged((AutomationElement)src);
        }
Esempio n. 18
0
 /// -------------------------------------------------------------------
 /// <summary></summary>
 /// -------------------------------------------------------------------
 void OnFocusChanged(object o, AutomationFocusChangedEventArgs e)
 {
     AutomationElement focusedElement = (AutomationElement)o;
     m_FocusEvents.Add(focusedElement);
     m_NotifiedEvent.Set();
 }
Esempio n. 19
0
        private void OnFocusChange(object sender, AutomationFocusChangedEventArgs e)
        {
            _currentElement = AutomationElement.FocusedElement;
            if (_currentElement == null)
                return;

            // Limit to VS WPF editors
            if (_currentElement.Current.AutomationId != "WpfTextView")
                return;

            this.UiFeedback(
                string.Format("hooking into control {0}, {2} in ProcessId {1}", _currentElement.Current.AutomationId, _currentElement.Current.ProcessId, _currentElement.Current.ControlType.ProgrammaticName));

            this.RemoveTextSelectionChangedEventHandlerIfSet();
            this.AddTextSelectionChangedEventHandler();

            this.RemoveTextChangedEventHandlerIfSet();
            this.AddTextChangedEventHandler();
        }
Esempio n. 20
0
 public void HandleEvent(object sender, AutomationFocusChangedEventArgs e)
 {
     OnMatchingEvent((AutomationElement)sender);
 }
Esempio n. 21
0
		public void AutomationFocusChangedEventArgsTest ()
		{
			var args = new AutomationFocusChangedEventArgs (0, 0);
			Assert.AreEqual (AutomationElementIdentifiers.AutomationFocusChangedEvent,
			                 args.EventId);
		}
Esempio n. 22
0
 internal InternalAutomationFocusChangedEventArgs(int idObject, int idChild, uint eventTime)
     : base(idObject, idChild)
 {
     _args = new AutomationFocusChangedEventArgs(idObject, idChild);
     _eventTime = eventTime;
 }
Esempio n. 23
0
        private static void userEventListner(object src, AutomationFocusChangedEventArgs args)
        {
            try
            {
                DateTime startTime = DateTime.Now;
                element = src as AutomationElement;
                if (element != null)
                {
                    /*** get the main window title of focus element ***/
                    int processId = element.Current.ProcessId;
                    Process process = Process.GetProcessById(processId);

                    string mainWindowTitle = null;
                    if (packages.Contains(process.ProcessName))
                        mainWindowTitle = process.ProcessName;
                    else
                        mainWindowTitle = process.MainWindowTitle;

                    /*** get the activity object corresponding to main window title ***/
                    Activity currentActivity = null;
                    if (activityList.ContainsKey(mainWindowTitle))
                    {
                        currentActivity = activityList[mainWindowTitle];
                        //activityList.Remove(mainWindowTitle);
                    }
                    else
                    {
                        currentActivity = new Activity();
                        currentActivity.processName = process.ProcessName;
                        activityList.Add(mainWindowTitle, currentActivity);
                    }

                    if (lastWindowName != null)
                    {
                        if (lastWindowName == mainWindowTitle)
                        {
                            currentActivity.endTime = startTime;
                            currentActivity.generateDuration();
                        }
                        else
                        {
                            activityList[lastWindowName].endTime = startTime;
                            activityList[lastWindowName].generateDuration();
                        }
                    }
                    currentActivity.startTime = startTime;
                    lastWindowName = mainWindowTitle;
                }
                Console.WriteLine("-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
                foreach (KeyValuePair<string, Activity> pair in activityList)
                {
                    Console.WriteLine(pair.Value.processName.PadRight(30) + pair.Value.duration.ToString().PadRight(20) + pair.Key);
                }
            }
            catch (Exception e)
            {
                return ;
            }
        }