Keyboard

Playwright\Input\KeyboardInterface

Sends keyboard input to a page. Operations target the focused element in the associated page. Key combinations and text entry use different browser event sequences.

Methods

insertText()

void

Inserts the text as-is: only an input event fires, no keydown/keyup.

function insertText(string $text): void

down()

void

Presses a key. The key remains pressed until a matching up() call. Modifier keys affect subsequent keyboard operations while held.

function down(string $key): void

press()

void

Presses and releases a key. Supports key combinations such as Control+S through the key argument. Options configure the delay and other browser input behavior.

function press(string $key, array $options = []): void

type()

void

Types text character by character. Browser key events are emitted for each typed character. Options can configure the delay between those events.

function type(string $text, array $options = []): void

up()

void

Releases a key. The key must have been pressed by down() or a key combination. Releasing a modifier restores normal keyboard input behavior.

function up(string $key): void