Table of Contents

Interface IKeyboard

Namespace
PuppeteerSharp.Input
Assembly
PuppeteerSharp.dll

Keyboard provides an api for managing a virtual keyboard. The high level api is TypeAsync(string, TypeOptions), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.

For finer control, you can use DownAsync(string, DownOptions), UpAsync(string), and SendCharacterAsync(string) to manually fire events as if they were generated from a real keyboard.

public interface IKeyboard

Methods

DownAsync(string, DownOptions)

Dispatches a keydown event.

Task DownAsync(string key, DownOptions options = null)

Parameters

key string

Name of key to press, such as ArrowLeft. KeyDefinitions for a list of all key names.

options DownOptions

down options.

Returns

Task

Task.

Remarks

If key is a single character and no modifier keys besides Shift are being held down, a keypress/input event will also generated. The text option can be specified to force an input event to be generated. If key is a modifier key, Shift, Meta, Control, or Alt, subsequent key presses will be sent with that modifier active. To release the modifier key, use UpAsync(string) After the key is pressed once, subsequent calls to DownAsync(string, DownOptions) will have repeat set to true. To release the key, use UpAsync(string).

PressAsync(string, PressOptions)

Task PressAsync(string key, PressOptions options = null)

Parameters

key string

Name of key to press, such as ArrowLeft. KeyDefinitions for a list of all key names.

options PressOptions

press options.

Returns

Task

Task.

Remarks

If key is a single character and no modifier keys besides Shift are being held down, a keypress/input event will also generated. The Text option can be specified to force an input event to be generated. Modifier keys DO effect PressAsync(string, PressOptions). Holding down Shift will type the text in upper case.

SendCharacterAsync(string)

Dispatches a keypress and input event. This does not send a keydown or keyup event.

Task SendCharacterAsync(string charText)

Parameters

charText string

Character to send into the page.

Returns

Task

Task.

TypeAsync(string, TypeOptions)

Sends a keydown, keypress/input, and keyup event for each character in the text.

Task TypeAsync(string text, TypeOptions options = null)

Parameters

text string

A text to type into a focused element.

options TypeOptions

type options.

Returns

Task

Task.

Remarks

To press a special key, like Control or ArrowDown, use PressAsync(string, PressOptions).

UpAsync(string)

Dispatches a keyup event.

Task UpAsync(string key)

Parameters

key string

Name of key to release, such as ArrowLeft. See KeyDefinitions for a list of all key names.

Returns

Task

Task.