Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/pptr/src/Input.ts>Keyboard

Headless Chrome Deno API
Latest
class Keyboard
import { Keyboard } from "https://deno.land/x/pptr@1.2.0/src/Input.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
_client: CDPSession
private
_pressedKeys: Set<string>
_modifiers: number

Methods

private
_keyDescriptionForString(keyString: KeyInput): KeyDescription
private
_modifierBit(key: string): number
private
charIsKey(char: string): char is KeyInput
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.