Skip to main content
Module

x/puppeteer/mod.ts>Keyboard

A port of puppeteer running on Deno
Latest
class Keyboard
Re-export
import { Keyboard } from "https://deno.land/x/puppeteer@16.2.0/mod.ts";

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

Examples

An example of holding down Shift in order to select and delete some text:

await page.keyboard.type('Hello World!');
await page.keyboard.press('ArrowLeft');

await page.keyboard.down('Shift');
for (let i = 0; i < ' World'.length; i++)
  await page.keyboard.press('ArrowLeft');
await page.keyboard.up('Shift');

await page.keyboard.press('Backspace');
// Result text will end up saying 'Hello!'

An example of pressing A

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

Constructors

new
Keyboard(client: CDPSession)

Properties

private
charIsKey
_modifiers: number

Methods

down(key: KeyInput, options?: { text?: string; }): Promise<void>

Dispatches a keydown event.

press(key: KeyInput, options?: { delay?: number; text?: string; }): Promise<void>

Shortcut for Keyboard.down and Keyboard.up.

sendCharacter(char: string): Promise<void>

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

type(text: string, options?: { delay?: number; }): Promise<void>

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

up(key: KeyInput): Promise<void>

Dispatches a keyup event.