new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Playwright · API reference · all subjects

keyboard

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Keyboard class overview

The Keyboard class provides an API for managing a virtual keyboard. It was introduced in v1.8. The high-level API is the type method, which takes raw characters and generates proper keydown, keypress/input, and keyup events on the page. For finer control, you can use the down, up, and insertText methods to manually fire events as if they were generated from a real keyboard.

Keyboard example - select and delete text with Shift

This example shows how to hold down Shift to select and delete text: JavaScript: ```js 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!' ``` Python (async): ```python await page.keyboard.type("Hello World!") await page.keyboard.press("ArrowLeft") await page.keyboard.down("Shift") for i in range(6): await page.keyboard.press("ArrowLeft") await page.keyboard.up("Shift") await page.keyboard.press("Backspace") # result text will end up saying "Hello!" ```

Keyboard example - press uppercase letter

This example shows how to press uppercase A: JavaScript: ```js await page.keyboard.press('Shift+KeyA'); // or await page.keyboard.press('Shift+A'); ``` Python (async): ```python await page.keyboard.press("Shift+KeyA") # or await page.keyboard.press("Shift+A") ```

Keyboard example - select all

This example shows how to trigger select-all with the keyboard: JavaScript: ```js await page.keyboard.press('ControlOrMeta+A'); ``` Python (async): ```python await page.keyboard.press("ControlOrMeta+A") ```

Keyboard example - type method

This example shows how to use the type method with and without delay: JavaScript: ```js await page.keyboard.type('Hello'); // Types instantly await page.keyboard.type('World', { delay: 100 }); // Types slower, like a user ``` Python (async): ```python await page.keyboard.type("Hello") # types instantly await page.keyboard.type("World", delay=100) # types slower, like a user ```

Keyboard example - insertText method

This example shows how to use the insertText method: JavaScript: ```js page.keyboard.insertText('嗨'); ``` Python (async): ```python await page.keyboard.insert_text("嗨") ```

Keyboard example - press method

This example shows how to use the press method for multiple key sequences: JavaScript: ```js const page = await browser.newPage(); await page.goto('https://keycode.info'); await page.keyboard.press('A'); await page.screenshot({ path: 'A.png' }); await page.keyboard.press('ArrowLeft'); await page.screenshot({ path: 'ArrowLeft.png' }); await page.keyboard.press('Shift+O'); await page.screenshot({ path: 'O.png' }); await browser.close(); ``` Python (async): ```python page = await browser.new_page() await page.goto("https://keycode.info") await page.keyboard.press("a") await page.screenshot(path="a.png") await page.keyboard.press("ArrowLeft") await page.screenshot(path="arrow_left.png") await page.keyboard.press("Shift+O") await page.screenshot(path="o.png") await browser.close() ```

Give your agent this brain