KeyboardInput Class

The keyboard of the user agent (see UserInput.Keyboard). The keys are dispatched to the focused element of the top-level browsing context (or to the body of the focused document), as trusted keydown, keypress and keyup events, and the library runs their default actions: the insertion of the text of the key in a text control or in editable content, the deletion of Backspace and Delete, the sequential focus navigation of Tab, the activation of the focused element by Enter and Space, the caret movements of the arrow keys, Home and End, the close requests of Escape, and the clipboard shortcuts (Control or Meta with C, X and V). The modifier keys that are pressed are the modifiers of the events (and of the pointer events, see UserInput.Modifiers).

public sealed class KeyboardInput

Properties

NameDescription
PressedKeysGets the keys that are pressed (their key values), in the order they were pressed.

Gets the keys that are pressed (their key values), in the order they were pressed.

public IReadOnlyList<string> PressedKeys { get; }

Property value

IReadOnlyList<string>

Methods

NameDescription
Down(KeyboardKey)Presses a key described by the values of its keyboard events (see KeyboardInput.Down): its key value is used as is (the Shift key does not change it).
Down(string)Presses a key: the keydown event, then the keypress event and the insertion of its text (a character key or Enter, not pressed with Control or Meta), or the default action of the key. A key that is already pressed repeats (the repeat attribute of the events is true). A letter pressed while Shift is pressed is an uppercase letter.
InsertText(string)Inserts a text in the focused text control or editable content, as an input method that commits a text: the beforeinput and input events of an insertText edit, without keyboard events.
Press(string)Presses and releases a key (see KeyboardInput.Down and KeyboardInput.Up).
Type(string)Types a text: presses and releases the key of each character (a line feed or a carriage return is the Enter key). The characters that a US keyboard cannot type are typed as keys that have no code.
Up(KeyboardKey)Releases a key described by the values of its keyboard events (see KeyboardInput.Up).
Up(string)Releases a key: the keyup event. A key that is not pressed is released anyway.

Down overloads

Down(KeyboardKey)

UserInput.Keyboard.cs

Presses a key described by the values of its keyboard events (see KeyboardInput.Down): its key value is used as is (the Shift key does not change it).

public void Down(KeyboardKey key)
Parameters
key KeyboardKey

Presses a key: the keydown event, then the keypress event and the insertion of its text (a character key or Enter, not pressed with Control or Meta), or the default action of the key. A key that is already pressed repeats (the repeat attribute of the events is true). A letter pressed while Shift is pressed is an uppercase letter.

public void Down(string key)
Parameters
key string
The key value (https://w3c.github.io/uievents-key/): a character (e.g. a) or the name of a key (e.g. Enter, Shift, ArrowLeft).

InsertText(string)

UserInput.Keyboard.cs

Inserts a text in the focused text control or editable content, as an input method that commits a text: the beforeinput and input events of an insertText edit, without keyboard events.

public void InsertText(string text)

Parameters

text string
The text.

Presses and releases a key (see KeyboardInput.Down and KeyboardInput.Up).

public void Press(string key)

Parameters

key string
The key value of the key.

Types a text: presses and releases the key of each character (a line feed or a carriage return is the Enter key). The characters that a US keyboard cannot type are typed as keys that have no code.

public void Type(string text)

Parameters

text string
The text.

Up overloads

Up(KeyboardKey)

UserInput.Keyboard.cs

Releases a key described by the values of its keyboard events (see KeyboardInput.Up).

public void Up(KeyboardKey key)
Parameters
key KeyboardKey

Releases a key: the keyup event. A key that is not pressed is released anyway.

public void Up(string key)
Parameters
key string
The key value of the key (see KeyboardInput.Down).