Skip to main content
The Keyboard class provides methods to simulate keyboard input such as typing text and pressing keys. Access the Keyboard instance through page.keyboard.

Methods

type

Types text character by character.
await page.keyboard.type('Hello World');
await page.keyboard.type('text', { delay: 100 });
text
string
required
The text to type
options.delay
number
Time to wait between key presses in milliseconds. Defaults to 0.

press

Presses a single key or a key combination.
await page.keyboard.press('Enter');
await page.keyboard.press('Control+A');
await page.keyboard.press('Shift+ArrowLeft');
key
string
required
The key or key combination to press. See key values for valid values.
options.delay
number
Time to wait between keydown and keyup in milliseconds. Defaults to 0.

down

Holds down a key.
await page.keyboard.down('Shift');
await page.keyboard.press('A');
await page.keyboard.up('Shift');
key
string
required
The key to hold down. See key values for valid values.

up

Releases a key.
await page.keyboard.down('Shift');
await page.keyboard.press('A');
await page.keyboard.up('Shift');
key
string
required
The key to release. See key values for valid values.

insertText

Inserts text without simulating key presses.
await page.keyboard.insertText('Hello World');
text
string
required
The text to insert
This method dispatches an input event directly, which is much faster than type() but does not trigger keydown, keypress, or keyup events.

Example Usage

Type Text with Delay

await page.keyboard.type('Hello World', { delay: 100 });

Keyboard Shortcuts

// Select all text
await page.keyboard.press('Control+A');

// Copy text
await page.keyboard.press('Control+C');

// Paste text
await page.keyboard.press('Control+V');

Hold Modifier Keys

await page.keyboard.down('Shift');
await page.keyboard.press('KeyA');
await page.keyboard.press('KeyB');
await page.keyboard.press('KeyC');
await page.keyboard.up('Shift');

Press Special Keys

await page.keyboard.press('Enter');
await page.keyboard.press('Tab');
await page.keyboard.press('Escape');
await page.keyboard.press('ArrowDown');

Build docs developers (and LLMs) love