Exemplo n.º 1
0
        public static void InvokeAndWait(this Button button, TimeSpan?timeout = null)
        {
            if (button == null)
            {
                Log.Error("Attempted to invoke a null button! Dumping context...");
                DumpHelper.DumpFullContext();
                throw new ArgumentNullException("button");
            }

            using (var waiter = button.GetInvokedWaiter())
            {
                button.Invoke();
                if (timeout == null)
                {
                    waiter.Wait();
                }
                else
                {
                    waiter.Wait(timeout.Value);
                }
            }

            Wait.ForIdle();
        }
Exemplo n.º 2
0
        public static void InvokeAndWait(this MenuItem menuItem, TimeSpan?timeout = null)
        {
            if (menuItem == null)
            {
                Log.Error("Attempted to invoke a null MenuItem! Dumping context...");
                DumpHelper.DumpFullContext();
                throw new ArgumentNullException("menuItem");
            }

            using (var waiter = menuItem.GetInvokedWaiter())
            {
                menuItem.Invoke();
                if (timeout == null)
                {
                    waiter.Wait();
                }
                else
                {
                    waiter.Wait(timeout.Value);
                }
            }

            Wait.ForIdle();
        }
Exemplo n.º 3
0
 public static void LeftDoubleClick(UIObject obj, double offsetX, double offsetY)
 {
     Log.Comment("Left double-click on {0}, at ({1}, {2}).", obj.GetIdentifier(), offsetX, offsetY);
     obj.DoubleClick(PointerButtons.Primary, offsetX, offsetY);
     Wait.ForIdle();
 }
Exemplo n.º 4
0
 public static void LeftDoubleClick(UIObject obj)
 {
     Log.Comment("Left double-click on {0}.", obj.GetIdentifier());
     obj.DoubleClick(PointerButtons.Primary);
     Wait.ForIdle();
 }
Exemplo n.º 5
0
 public static void RotateWheel(UIObject obj, int mouseWheelDelta)
 {
     Log.Comment("RotateWheel on {0} with mouseWheelDelta: {1}.", obj.GetIdentifier(), mouseWheelDelta);
     MouseWheelInput.RotateWheel(obj, mouseWheelDelta);
     Wait.ForIdle();
 }
        public static void PressKey(UIObject obj, Key key, ModifierKey modifierKey = ModifierKey.None, uint numPresses = 1, bool useDebugMode = false)
        {
            using (var waiter = GetWaiterForKeyEvent(obj, key))
            {
                if (useDebugMode)
                {
                    Log.Comment("PressKey uses waiter: {0}.", waiter != null);
                }

                if (waiter != null)
                {
                    for (int i = 0; i < numPresses; i++)
                    {
                        string keystrokes = ApplyModifierKey(keyToKeyStringDictionary[key], modifierKey);

                        Log.Comment("Send text '{0}'.", keystrokes);
                        obj.SendKeys(keystrokes);

                        waiter.Wait();
                        waiter.Reset();
                        Wait.ForIdle();
                    }
                }
                else
                {
                    string keystrokes = string.Empty;

                    for (int i = 0; i < numPresses; i++)
                    {
                        keystrokes += keyToKeyStringDictionary[key];
                    }

                    keystrokes = ApplyModifierKey(keystrokes, modifierKey);

                    Log.Comment("Send text '{0}'.", keystrokes);

                    try
                    {
                        obj.SendKeys(keystrokes);
                    }
                    catch (Exception e)
                    {
                        if (useDebugMode)
                        {
                            Log.Comment("UIObject.SendKey threw exception: {0}", e.ToString());
                            Log.Comment("Send text (2)."); // Attempting to send text again to check if it succeeds this time.
                            obj.SendKeys(keystrokes);
                            Log.Comment("Text sent (2).");
                        }

                        throw;
                    }

                    if (useDebugMode)
                    {
                        Log.Comment("Text sent.");
                    }

                    Wait.ForIdle();
                }
            }

            if (useDebugMode)
            {
                Log.Comment("Exiting PressKey.");
            }
        }