コード例 #1
0
        public static void HoldKeyMilliSeconds(Key key, uint milliseconds, ModifierKey modifierKey = ModifierKey.None, bool useDebugMode = false)
        {
            if (useDebugMode)
            {
                Log.Comment("Holding down key: {0} for {1} milliseconds.", key, milliseconds);
            }
            // Remove starting and ending curly bracket.
            var cleanedName = keyToKeyStringDictionary[key].Substring(1).Replace("}", "");

            string beginKeyStroke = GetPressDownModifierKeyStroke(modifierKey) + "{" + cleanedName + " DOWN}";
            string endKeyStroke   = "{" + cleanedName + " UP}" + GetReleaseModifierKeyStroke(modifierKey);

            TextInput.SendText(beginKeyStroke);

            Wait.ForMilliseconds(milliseconds);

            TextInput.SendText(endKeyStroke);

            if (useDebugMode)
            {
                Log.Comment($"Pressed key for {milliseconds} milliseconds.");
            }

            Wait.ForIdle();

            if (useDebugMode)
            {
                Log.Comment("Exiting HoldKeyForMilliSeconds.");
            }
        }
コード例 #2
0
        public static void PressButton(UIObject obj, GamepadButton button)
        {
            Log.Comment("Pressing Gamepad button: {0}", button);
            KeyboardInput[] array = new KeyboardInput[1];
            array[0].virtualKeyCode = (ushort)button;
            InternalNativeMethods.InjectKeyboardInput(array, 1);

            // Without a delay, the input gets dropped.
            Wait.ForMilliseconds(50);

            array[0].flags = KEY_EVENT_FLAGS.KEYUP;
            InternalNativeMethods.InjectKeyboardInput(array, 1);
        }
コード例 #3
0
 public static void TapAndHold(UIObject obj, uint durationMs)
 {
     Log.Comment("Tap and hold on {0} for {1} ms.", obj.GetIdentifier(), durationMs);
     using (var waiter = GetWaiterForInputEvent(obj, InputEvent.Tap))
     {
         if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
         {
             Log.Warning("Touch input is not available on OS versions less than RS5. Falling back to mouse input.");
             PointerInput.Move(obj);
             PointerInput.Press(PointerButtons.Primary);
             Wait.ForMilliseconds(durationMs);
             PointerInput.Release(PointerButtons.Primary);
         }
         else
         {
             obj.TapAndHold(durationMs);
         }
     }
     Wait.ForIdle();
 }
コード例 #4
0
        public static void PressButton(UIObject obj, GamepadButton button)
        {
            var keyInputReceivedUIObject = FindElement.ById("__KeyInputReceived");

            if (keyInputReceivedUIObject != null)
            {
                var keyInputReceivedCheckbox = new CheckBox(keyInputReceivedUIObject);

                if (keyInputReceivedCheckbox.ToggleState == ToggleState.On)
                {
                    keyInputReceivedCheckbox.Uncheck();
                }
                Verify.IsTrue(keyInputReceivedCheckbox.ToggleState == ToggleState.Off);
            }

            Log.Comment("Pressing Gamepad button: {0}", button);
            KeyboardInput[] array = new KeyboardInput[1];
            array[0].virtualKeyCode = (ushort)button;
            InternalNativeMethods.InjectKeyboardInput(array, 1);


            // Wait until app reports it received the input
            if (keyInputReceivedUIObject == null)
            {
                // Fallback if we don't find out helper
                Wait.ForMilliseconds(50);
            }
            else
            {
                var keyInputReceivedCheckbox = new CheckBox(keyInputReceivedUIObject);
                keyInputReceivedCheckbox.GetToggledWaiter().TryWait(TimeSpan.FromMilliseconds(50));
            }

            Wait.ForIdle();
            array[0].flags = KEY_EVENT_FLAGS.KEYUP;
            InternalNativeMethods.InjectKeyboardInput(array, 1);
        }