Exemplo n.º 1
0
        private void FireFoxChildWindowOpened(object sender, AutomationEventArgs e)
        {
            var element = sender as AutomationElement;

            if (element == null)
            {
                return;
            }

            // Filter for a proxy message
            if (!MatchWindow(element, PROXY_CLASSNAME, PROXY_AUTOMATIONID, PROXY_NAME))
            {
                return;
            }

            // Find the cancel button
            var controls     = element.FindAll(TreeScope.Children, Condition.TrueCondition).ToList();
            var cancelButton = controls.FirstOrDefault(c => c.Current.ControlType == ControlType.Button && c.Current.Name == "Cancel");

            if (cancelButton == null)
            {
                return;
            }

            // Get the click pattern
            object clickPatternObj;

            if (!cancelButton.TryGetCurrentPattern(InvokePattern.Pattern, out clickPatternObj))
            {
                return;
            }
            ((InvokePattern)clickPatternObj).Invoke();     // click the cancel button
        }
Exemplo n.º 2
0
        private void OnEvent(object src, AutomationEventArgs e)
        {
            AutomationElement el = src as AutomationElement;

            string itemType = el.Current.ClassName;
            string id       = el.Current.AutomationId;
            string text     = this.GetText((src as AutomationElement));

            if (e.EventId == InvokePattern.InvokedEvent)
            {
                Activity act = new Activity()
                {
                    Type = Activity.Types.Click,
                    ControlDisplayText = text,
                    ControlType        = itemType,
                    WPath = this.GetWPath(this.GetAncestorWalk(el))
                };
                this.m_Activities.Add(act);
            }
            else if (e.EventId == SelectionPattern.InvalidatedEvent)
            {
                Activity act = new Activity()
                {
                    Type = Activity.Types.SelectionChange,
                    ControlDisplayText = text,
                    ControlType        = itemType,
                    WPath = this.GetWPath(this.GetAncestorWalk(el))
                };
                this.m_Activities.Add(act);
            }
        }
 private void MessageBoxButtonHandler(object sender, AutomationEventArgs e)
 {
     Console.WriteLine("Dialog Button clicked at : " + DateTime.Now.ToString());
     // (...)
     // Remove the handler after, since the next MessageBox needs a new handler.
     Automation.RemoveAutomationEventHandler(e.EventId, buttonElement, DialogButtonHandler);
 }
Exemplo n.º 4
0
        public bool WaitFor(AutomationElementWrapper element, SomethingToWaitFor check, TimeSpan timeout, FailureToHappenHandler failureHandler, IEnumerable <AutomationEventWrapper> events)
        {
            Monitor.Enter(_waitingRoom);
            _triggeringEvent = null;

            DateTime started         = DateTime.Now;
            var      handlerRemovers = AddPulsingHandlers(events, element);

            bool checkPassed = true;

            while (!check(element, _triggeringEvent) && DateTime.Now.Subtract(started).CompareTo(timeout) < 0)
            {
                checkPassed = false;
                Monitor.Wait(_waitingRoom, timeout);
            }
            Monitor.Exit(_waitingRoom);
            ClearPulsingHandlers(handlerRemovers);

            if (!checkPassed && !check(element, null))
            {
                failureHandler(element);
                return(false);
            }
            return(true);
        }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal CalloutQueueItem(Delegate clientCallback, UiaCoreApi.UiaCacheResponse cacheResponse, AutomationEventArgs e, UiaCoreApi.UiaCacheRequest cacheRequest)
        {
            _clientCallback = clientCallback;
            _cacheResponse  = cacheResponse;
            _e            = e;
            _cacheRequest = cacheRequest;
        }
Exemplo n.º 6
0
        private void OnWindowOpened(object sender, AutomationEventArgs automationEventArgs)
        {
            if (!configurationManager.ConfigFile.AutoApplyProfiles)
            {
                return;
            }

            var element = sender as AutomationElement;

            if (element == null)
            {
                return;
            }

            var profile = configurationManager.ConfigFile.WindowProfiles.SingleOrDefault(p => new Regex(p.TitleRegex).IsMatch(element.Current.Name));

            if (profile == null)
            {
                return;
            }

            var process = Process.GetProcessById(element.Current.ProcessId);

            if (process == null || !process.ProcessName.Equals(profile.ProcessName))
            {
                return;
            }

            ApplyWindowComposition(element.Current.NativeWindowHandle, profile.WindowComposition);
        }
Exemplo n.º 7
0
        // Runs on an automation event thread
        void PopupListElementSelectedHandler(object sender, AutomationEventArgs e)
        {
            Logger.WindowWatcher.Verbose($"PopupList PopupListElementSelectedHandler on thread {Thread.CurrentThread.ManagedThreadId}");
            var selectedItem = (AutomationElement)sender;

            UpdateSelectedItem(selectedItem);
        }
Exemplo n.º 8
0
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        #region Private Methods

        private static void OnToolTipEvents(IntPtr hwnd, int eventId, object idProp, int idObject, int idChild)
        {
            if (idObject != NativeMethods.OBJID_WINDOW)
            {
                return;
            }

            if (!IsToolTip(hwnd))
            {
                return;
            }

            // Raise ToolTipClosedEvent on OBJECT_HIDE WinEvents.  Not raising the event for EVENT_OBJECT_DESTROY
            // because to do this means having to change code downstream from RaiseAutomationEvent to accept a
            // null src.  PS #1007309 (Client-side proxies that raise events end up going through server-side
            // code) would be a good time to fix this issue (may then be able to pass null src).  Most tool tips
            // currently get created, then shown and hidden, and are destroyed when the app exits so the impact
            // here should be minimal since the ToolTip is probaby not showing when the app exits.
            if (eventId == NativeMethods.EVENT_OBJECT_HIDE /*|| eventId == NativeMethods.EVENT_OBJECT_DESTROY*/)
            {
                WindowsTooltip      wtv = new WindowsTooltip(hwnd, null, 0);
                AutomationEventArgs e   = new AutomationEventArgs(AutomationElement.ToolTipClosedEvent);
                AutomationInteropProvider.RaiseAutomationEvent(AutomationElement.ToolTipClosedEvent, wtv, e);
            }
        }
Exemplo n.º 9
0
        public void DoSubWindowOpenAction(object src, AutomationEventArgs e)
        {
            AutomationElement subWindow = null;
            String            subWinTitle;
            AutomationElement button = null;
            AutomationElement element;

            try
            {
                subWinTitle = Init.GetSubWinTitle();

                element = src as AutomationElement;

                if (!Regex.IsMatch(element.Current.Name, subWinTitle))
                {
                    return;
                }
            }
            catch (ElementNotAvailableException)
            {
                return;
            }

            if (e.EventId == WindowPattern.WindowOpenedEvent)
            {
                Init.SetSubWinTitle(subWinTitle);
                subWindow = element;
                Init.SetSubWindow(subWindow);
                subWindow = Init.GetSubWindow();
                Init.SetButton();
                button = Init.GetButton();
                RegisterButtonClickEvent(button);
            }
        }
Exemplo n.º 10
0
        //#endregion Invoke-UiaScript

        protected virtual void SaveEventInput(
            AutomationElement src,
            AutomationEventArgs e,
            string programmaticName,
            bool infoAdded)
        {
        }
Exemplo n.º 11
0
        public void DoMainWindowOpenAction(object src, AutomationEventArgs e)
        {
            String            mainWinTitle;
            AutomationElement mainWindow = null;
            AutomationElement element;

            try
            {
                mainWinTitle = Init.GetMainWinTitle();

                element = src as AutomationElement;



                if (!Regex.IsMatch(element.Current.Name, mainWinTitle, RegexOptions.IgnoreCase))
                {
                    return;
                }
            }
            catch (ElementNotAvailableException)
            {
                return;
            }

            if (e.EventId == WindowPattern.WindowOpenedEvent)
            {
                Init.SetMainWinTitle(element.Current.Name);
                mainWindow = element;
                Init.SetmainWindow(mainWindow);
                mainWindow = Init.GetmainWindow();
                RegisterSubWinOpenEvent(mainWindow);
            }
        }
Exemplo n.º 12
0
        public void DoMainWindowCloseAction(object src, AutomationEventArgs e)
        {
            String mainWinTitle;

            try
            {
                mainWinTitle = Init.GetMainWinTitle();

                var element = src as AutomationElement;

                if (!(element.Current.Name == mainWinTitle))
                {
                    return;
                }
            }
            catch (ElementNotAvailableException)
            {
                return;
            }

            if (e.EventId == WindowPattern.WindowClosedEvent)
            {
                // TODO: event handling
            }
        }
Exemplo n.º 13
0
        private void OnWindowOpened(object sender, AutomationEventArgs e)
        {
            var element = sender as AutomationElement;

            if ((element == null) || !string.Equals(element.Current.Name, _codeSignerSettings.ProgramName, StringComparison.Ordinal))
            {
                return;
            }

            var pattern = (WindowPattern)element.GetCurrentPattern(WindowPattern.Pattern);

            pattern.WaitForInputIdle(10000);
            var edit = element.FindFirst(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), new PropertyCondition(AutomationElement.NameProperty, _codeSignerSettings.PasswordBoxName)));
            var ok   = element.FindFirst(TreeScope.Descendants, new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, _codeSignerSettings.AcceptButtonContent)));

            if ((edit != null) && (ok != null))
            {
                var vp = (ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern);
                vp.SetValue(_storedPassword.ToInsecureString());
                var ip = (InvokePattern)ok.GetCurrentPattern(InvokePattern.Pattern);
                ip.Invoke();
            }
            else
            {
                _log?.WriteEntry("CodeSignerPasswordService stopping...", EventLogEntryType.Information);
                Console.WriteLine("SafeNet window detected but could not find password box and/or 'OK' button");
            }
        }
Exemplo n.º 14
0
        private static void AutoCorrect(object sender, AutomationEventArgs e)
        {
            var element = (AutomationElement)sender;

            string originalText = element.GetText();
            string newText      = originalText;

            if (newText.EndsWith("."))
            {
                foreach (var replacement in REPLACEMENTS)
                {
                    if (newText.Contains(replacement.Key))
                    {
                        newText = newText.Replace(replacement.Key, replacement.Value);
                    }
                }
            }

            if (newText != originalText)
            {
                element.SetFocus();
                SendKeys.SendWait("^{HOME}");
                SendKeys.SendWait("^+{END}");
                SendKeys.SendWait("{DEL}");
                SendKeys.SendWait(newText);
            }
        }
Exemplo n.º 15
0
 public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs e)
 {
     if (eventId == InvokePatternIdentifiers.InvokedEvent ||
         eventId == SelectionItemPatternIdentifiers.ElementSelectedEvent)
     {
         if (!selected)
         {
             selected = true;
             NotifyStateChange(Atk.StateType.Selected, selected);
         }
         ((ICanHaveSelection)this).RecursivelyDeselectAll(this);
     }
     else if (eventId == AutomationElementIdentifiers.AutomationFocusChangedEvent)
     {
         selected = !selected;
         NotifyStateChange(Atk.StateType.Selected, selected);
         if (selected)
         {
             //this causes the following in accerciser: focus:(0, 0, None)
             Atk.Focus.TrackerNotify(this);
         }
         ((ICanHaveSelection)this).RecursivelyDeselectAll(selected ? this : null);
     }
     else
     {
         Log.Warn("MenuItem: RaiseAutomationEvent({0},...) not implemented", eventId.ProgrammaticName);
         base.RaiseAutomationEvent(eventId, e);
     }
 }
Exemplo n.º 16
0
        // OnMenuEvent - Called by MenuTracker class
        private static void OnMenuEvent(AutomationElement rawEl, bool menuHasOpened)
        {
            AutomationEvent     eventId = menuHasOpened ? AutomationElement.MenuOpenedEvent : AutomationElement.MenuClosedEvent;
            AutomationEventArgs e       = new AutomationEventArgs(eventId);

            RaiseEventInThisClientOnly(eventId, rawEl, e);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Event handler for the structure changed event.
 /// </summary>
 private static void OnStructureChanged(object src, AutomationEventArgs e)
 {
     if ((src as AutomationElement).Current.Name == "Wunderlist")
     {
         eventControl?.Set();
     }
 }
Exemplo n.º 18
0
        public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs e)
        {
            if (eventId == TextPatternIdentifiers.TextChangedEvent)
            {
                string newText = Provider.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id) as string;

                // Don't fire spurious events if the text hasn't changed
                if (textExpert.Text == newText)
                {
                    return;
                }

                // First delete all text, then insert the new text
                textExpert.EmitTextChanged(Atk.TextChangedDetail.Delete, 0, textExpert.Length);

                textExpert.EmitTextChanged(Atk.TextChangedDetail.Insert, 0,
                                           newText == null ? 0 : newText.Length);

                // Accessible name and label text are one and
                // the same, so update accessible name
                Name = newText;

                EmitVisibleDataChanged();
            }
        }
Exemplo n.º 19
0
        public override void RaiseAutomationEvent(AutomationEvent eventId, AutomationEventArgs e)
        {
            if (editableTextExpert.RaiseAutomationEvent(eventId, e))
            {
                return;
            }

            if (eventId == SelectionItemPatternIdentifiers.ElementSelectedEvent)
            {
                List list = Parent as List;
                if (list != null)
                {
                    list.NotifyItemSelected(this);
                }
                else
                {
                    NotifyStateChange(Atk.StateType.Selected, true);
                }
            }
            else if (eventId == SelectionItemPatternIdentifiers.ElementAddedToSelectionEvent)
            {
                NotifyStateChange(Atk.StateType.Selected, true);
            }
            else if (eventId == SelectionItemPatternIdentifiers.ElementRemovedFromSelectionEvent)
            {
                NotifyStateChange(Atk.StateType.Selected, false);
            }
        }
Exemplo n.º 20
0
        private void SelectionChanged(object sender, AutomationEventArgs e)
        {
            AutomationElement element = sender as AutomationElement;

            if (AutomationEventHandlerGuard(element))
            {
                return;
            }

            AutomationElement parent = GetExplorerWindow(element);

            if (parent != null)
            {
                IntPtr hwnd = new IntPtr(parent.Current.NativeWindowHandle);

                string[] items = ExplorerAdapter.GetSelectedItems(hwnd);

                if (items != null)
                {
                    if (ExplorerSelectionChanged != null)
                    {
                        ExplorerSelectionChanged(this, items);
                    }
                }
            }
        }
Exemplo n.º 21
0
 private void OnWindowDelete(object sender, AutomationEventArgs e)
 {
     /*
      * Delete window handle that exist in the list on window close event
      * */
     try
     {
         AutomationElement element = sender as AutomationElement;
         if (e.EventId == WindowPattern.WindowClosedEvent)
         {
             if (element != null)
             {
                 string windowName = element.Current.Name;
                 int[]  rid        = element.GetRuntimeId();
                 common.LogMessage("Removed: " +
                                   element.Current.ControlType.ProgrammaticName +
                                   " : " + windowName + " : " + rid);
                 if (this.IndexOf(element) != -1)
                 {
                     this.Remove(element);
                 }
                 common.LogMessage("Removed - Window list count: " +
                                   this.Count);
             }
         }
     }
     catch
     {
         // Since window list is added / removed in different thread
         // values of windowList might be altered and an exception is thrown
         // Just handle the global exception
     }
 }
Exemplo n.º 22
0
 private static void OnWindowOpened(object sender, AutomationEventArgs automationEventArgs)
 {
     try
     {
         var element = sender as AutomationElement;
         if (element != null)
         {
             if (element.Current.Name.Trim() == "Editor for A Hat in Time (64-bit, DX9, Cooked Editor, PMT)")
             {
                 if (Benchmark != null)
                 {
                     Benchmark.Stop();
                 }
                 Meme.StopElevatorMusic();
             }
             else if (element.Current.Name.Trim() == "Editor for A Hat in Time (64-bit, DX9)")
             {
                 Meme.PlayElevatorMusic();
             }
         }
     }
     catch (ElementNotAvailableException)
     {
     }
 }
Exemplo n.º 23
0
        /// <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;
            }
        }
Exemplo n.º 24
0
        ///--------------------------------------------------------------------
        /// <summary>
        /// AutomationEventHandler delegate.
        /// </summary>
        /// <param name="src">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        ///--------------------------------------------------------------------
        private void OnWindowOpenOrClose(object src, AutomationEventArgs e)
        {
            // Make sure the element still exists. Elements such as tooltips
            // can disappear before the event is processed.
            AutomationElement sourceElement;

            try
            {
                sourceElement = src as AutomationElement;
            }
            catch (ElementNotAvailableException)
            {
                return;
            }

            if (e.EventId == WindowPattern.WindowOpenedEvent)
            {
                // TODO: event handling
                return;
            }
            if (e.EventId == WindowPattern.WindowClosedEvent)
            {
                // TODO: event handling
                return;
            }
        }
Exemplo n.º 25
0
 private void onWindowOpened(object?sender, AutomationEventArgs e)
 {
     if (sender is AutomationElement windowEl)
     {
         onWindowOpened(windowEl.toSystemWindow());
     }
 }
        //------------------------------------------------------
        //
        //  Constructors
        //
        //------------------------------------------------------

        #region Constructors

        internal ClientSideQueueItem(Delegate clientCallback, AutomationElement srcEl, UiaCoreApi.UiaCacheRequest request, AutomationEventArgs e)
        {
            _clientCallback = clientCallback;
            _srcEl          = srcEl;
            _request        = request;
            _e = e;
        }
Exemplo n.º 27
0
        void OnWindowOpenOrClose(object src, AutomationEventArgs e)
        {
            if (e.EventId != WindowPattern.WindowOpenedEvent)
            {
                return;
            }

            AutomationElement sourceElement;

            try
            {
                sourceElement = src as AutomationElement;
                //Check the event source is caculator or not.
                //In production code, string should be read from resource to support localization testing.
                if (sourceElement.Current.Name == "计算器")
                {
                    calcWindow = sourceElement;
                }
            }
            catch (ElementNotAvailableException)
            {
                return;
            }
            //Start testing
            ExecuteTest();
        }
Exemplo n.º 28
0
 private void OnUIAutomationEvent(object src, AutomationEventArgs e)
 {
     if (!positionThread.IsAlive)
     {
         loop();
     }
 }
Exemplo n.º 29
0
 /// <summary>
 /// Window was closed.  Raise an event to indicate this
 /// </summary>
 /// <param name="sender">event sender</param>
 /// <param name="e">event ards</param>
 private void onWindowClose(object sender, AutomationEventArgs e)
 {
     if (EvtOnWindowClosed != null)
     {
         Log.Debug("Triggering event closed");
         EvtOnWindowClosed(_hwnd);
     }
 }
Exemplo n.º 30
0
 void PopupListElementSelectedHandler(object sender, AutomationEventArgs e)
 {
     _syncContext.Post(delegate
     {
         Debug.Print("### Thread receiving PopupListElementSelectedHandler: " + Thread.CurrentThread.ManagedThreadId);
         UpdateSelectedItem(sender as AutomationElement);
     }, null);
 }
Exemplo n.º 31
0
 public static void RaiseAutomationEvent(AutomationEvent eventId, IRawElementProviderSimple provider, AutomationEventArgs e)
 {
     Utility.ValidateArgumentNonNull(eventId, "eventId");
     Utility.ValidateArgumentNonNull(provider, "provider");
     Utility.ValidateArgumentNonNull(e, "e");
     if (e.EventId == AutomationElementIdentifiers.AsyncContentLoadedEvent)
     {
         AsyncContentLoadedEventArgs args = e as AsyncContentLoadedEventArgs;
         if (args == null)
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAsyncContentLoadedEvent(provider, args.AsyncContentLoadedState, args.PercentComplete);
     }
     else
     {
         if ((e.EventId == WindowPatternIdentifiers.WindowClosedEvent) && !(e is WindowClosedEventArgs))
         {
             throw new ArgumentException("e");
         }
         UiaCoreProviderApi.UiaRaiseAutomationEvent(provider, eventId.Id);
     }
 }