예제 #1
0
        /// <summary>
        /// Dispatches a <c>keydown</c> event
        /// </summary>
        /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. <see cref="KeyDefinitions"/> for a list of all key names.</param>
        /// <param name="options">down options</param>
        /// <remarks>
        /// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also generated. The <c>text</c> option can be specified to force an input event to be generated.
        /// If <c>key</c> is a modifier key, <c>Shift</c>, <c>Meta</c>, <c>Control</c>, or <c>Alt</c>, subsequent key presses will be sent with that modifier active. To release the modifier key, use <see cref="UpAsync(string)"/>
        /// After the key is pressed once, subsequent calls to <see cref="DownAsync(string, DownOptions)"/> will have <see href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat">repeat</see> set to <c>true</c>. To release the key, use <see cref="UpAsync(string)"/>
        /// </remarks>
        /// <returns>Task</returns>
        public Task DownAsync(string key, DownOptions options = null)
        {
            var description = KeyDescriptionForString(key);

            var autoRepeat = _pressedKeys.Contains(description.Code);

            _pressedKeys.Add(description.Code);
            Modifiers |= ModifierBit(key);

            var text = options?.Text == null ? description.Text : options.Text;

            return(_client.SendAsync("Input.dispatchKeyEvent", new Dictionary <string, object>
            {
                { MessageKeys.Type, text != null ? "keyDown" : "rawKeyDown" },
                { MessageKeys.Modifiers, Modifiers },
                { MessageKeys.WindowsVirtualKeyCode, description.KeyCode },
                { MessageKeys.Code, description.Code },
                { MessageKeys.Key, description.Key },
                { MessageKeys.Text, text },
                { MessageKeys.UnmodifiedText, text },
                { MessageKeys.AutoRepeat, autoRepeat },
                { MessageKeys.Location, description.Location },
                { MessageKeys.IsKeypad, description.Location == 3 }
            }));
        }
예제 #2
0
        /// <summary>
        /// Dispatches a <c>keydown</c> event
        /// </summary>
        /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. <see cref="KeyDefinitions"/> for a list of all key names.</param>
        /// <param name="options">down options</param>
        /// <remarks>
        /// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also generated. The <c>text</c> option can be specified to force an input event to be generated.
        /// If <c>key</c> is a modifier key, <c>Shift</c>, <c>Meta</c>, <c>Control</c>, or <c>Alt</c>, subsequent key presses will be sent with that modifier active. To release the modifier key, use <see cref="UpAsync(string)"/>
        /// After the key is pressed once, subsequent calls to <see cref="DownAsync(string, DownOptions)"/> will have <see href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat">repeat</see> set to <c>true</c>. To release the key, use <see cref="UpAsync(string)"/>
        /// </remarks>
        /// <returns>Task</returns>
        public Task DownAsync(string key, DownOptions options = null)
        {
            var description = KeyDescriptionForString(key);

            var autoRepeat = _pressedKeys.Contains(description.Code);

            _pressedKeys.Add(description.Code);
            Modifiers |= ModifierBit(key);

            var text = options?.Text == null ? description.Text : options.Text;

            return(_client.SendAsync("Input.dispatchKeyEvent", new InputDispatchKeyEventRequest
            {
                Type = text != null ? DispatchKeyEventType.KeyDown : DispatchKeyEventType.RawKeyDown,
                Modifiers = Modifiers,
                WindowsVirtualKeyCode = description.KeyCode,
                Code = description.Code,
                Key = description.Key,
                Text = text,
                UnmodifiedText = text,
                AutoRepeat = autoRepeat,
                Location = description.Location,
                IsKeypad = description.Location == 3
            }));
        }
예제 #3
0
        /// <summary>
        /// Dispatches a <c>keydown</c> event
        /// </summary>
        /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. <see cref="KeyDefinitions"/> for a list of all key names.</param>
        /// <param name="options">down options</param>
        /// <remarks>
        /// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also generated. The <c>text</c> option can be specified to force an input event to be generated.
        /// If <c>key</c> is a modifier key, <c>Shift</c>, <c>Meta</c>, <c>Control</c>, or <c>Alt</c>, subsequent key presses will be sent with that modifier active. To release the modifier key, use <see cref="UpAsync(string)"/>
        /// After the key is pressed once, subsequent calls to <see cref="DownAsync(string, DownOptions)"/> will have <see href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat">repeat</see> set to <c>true</c>. To release the key, use <see cref="UpAsync(string)"/>
        /// </remarks>
        /// <returns>Task</returns>
        public Task DownAsync(string key, DownOptions options = null)
        {
            var description = KeyDescriptionForString(key);

            var autoRepeat = _pressedKeys.Contains(description.Code);

            _pressedKeys.Add(description.Code);
            Modifiers |= ModifierBit(key);

            var text = options?.Text == null ? description.Text : options.Text;

            return(_client.SendAsync("Input.dispatchKeyEvent", new Dictionary <string, object>()
            {
                { "type", text != null ? "keyDown" : "rawKeyDown" },
                { "modifiers", Modifiers },
                { "windowsVirtualKeyCode", description.KeyCode },
                { "code", description.Code },
                { "key", description.Key },
                { "text", text },
                { "unmodifiedText", text },
                { "autoRepeat", autoRepeat },
                { "location", description.Location },
                { "isKeypad", description.Location == 3 }
            }));
        }