コード例 #1
0
 private void KeysPress(InputBuilder builder, IEnumerable <VirtualKeyCode> keyCodes)
 {
     if (keyCodes == null)
     {
         return;
     }
     foreach (VirtualKeyCode key in keyCodes)
     {
         builder.AddKeyPress(key);
     }
 }
コード例 #2
0
 private void ModifiersDown(InputBuilder builder, IEnumerable <VirtualKeyCode> modifierKeyCodes)
 {
     if (modifierKeyCodes == null)
     {
         return;
     }
     foreach (VirtualKeyCode key in modifierKeyCodes)
     {
         builder.AddKeyDown(key);
     }
 }
コード例 #3
0
 /// <summary>
 /// Calls the Win32 SendInput method with a stream of KeyDown and KeyUp messages in order to simulate uninterrupted text entry via the keyboard.
 /// </summary>
 /// <param name="text">The text to be simulated.</param>
 public IKeyboardSimulator TextEntry(string text)
 {
     if (text.Length > UInt32.MaxValue / 2)
     {
         throw new ArgumentException(
                   string.Format("The text parameter is too long. It must be less than {0} characters.",
                                 UInt32.MaxValue / 2), "text");
     }
     INPUT[] inputList = new InputBuilder().AddCharacters(text).ToArray();
     SendSimulatedInput(inputList);
     return(this);
 }
コード例 #4
0
        /// <summary>
        /// Simulates a modified keystroke where there are multiple modifiers and multiple keys like CTRL-ALT-K-C where CTRL and ALT are the modifierKeys and K and C are the keys.
        /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order.
        /// </summary>
        /// <param name="modifierKeyCodes">The list of modifier keys</param>
        /// <param name="keyCodes">The list of keys to simulate</param>
        public IKeyboardSimulator ModifiedKeyStroke(IEnumerable <VirtualKeyCode> modifierKeyCodes,
                                                    IEnumerable <VirtualKeyCode> keyCodes)
        {
            var builder = new InputBuilder();

            ModifiersDown(builder, modifierKeyCodes);
            KeysPress(builder, keyCodes);
            ModifiersUp(builder, modifierKeyCodes);

            SendSimulatedInput(builder.ToArray());
            return(this);
        }
コード例 #5
0
        private void ModifiersUp(InputBuilder builder, IEnumerable <VirtualKeyCode> modifierKeyCodes)
        {
            if (modifierKeyCodes == null)
            {
                return;
            }

            // Key up in reverse (I miss LINQ)
            var stack = new Stack <VirtualKeyCode>(modifierKeyCodes);

            while (stack.Count > 0)
            {
                builder.AddKeyUp(stack.Pop());
            }
        }
コード例 #6
0
 /// <summary>
 /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS.
 /// </summary>
 /// <param name="keyCode">The <see cref="VirtualKeyCode"/> to press</param>
 public IKeyboardSimulator KeyPress(VirtualKeyCode keyCode)
 {
     INPUT[] inputList = new InputBuilder().AddKeyPress(keyCode).ToArray();
     SendSimulatedInput(inputList);
     return(this);
 }
コード例 #7
0
 /// <summary>
 /// Simulates a single character text entry via the keyboard.
 /// </summary>
 /// <param name="character">The unicode character to be simulated.</param>
 public IKeyboardSimulator TextEntry(char character)
 {
     INPUT[] inputList = new InputBuilder().AddCharacter(character).ToArray();
     SendSimulatedInput(inputList);
     return(this);
 }