import { Keyboard } from "https://deno.land/x/pptr@1.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:
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
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)Methods
private
_keyDescriptionForString(keyString: KeyInput): KeyDescriptionprivate
_modifierBit(key: string): numberShortcut 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.