Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright Client Input

From Leeroopedia
Knowledge Sources
Domains Browser Automation, User Input Simulation
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for simulating keyboard, mouse, and touchscreen input on browser pages provided by the Playwright library.

Description

This module exports three input device classes, each bound to a Page and delegating to the page's channel:

  • Keyboard implements api.Keyboard with methods: down(key) to press a key, up(key) to release it, insertText(text) to insert text without key events, type(text, options) to type with key events and optional delay, and press(key, options) to press and release a key with optional delay.
  • Mouse implements api.Mouse with methods: move(x, y, options) for movement with optional steps, down(options) and up(options) for button press/release with optional button and click count, click(x, y, options) for click with configurable button/delay/click count, dblclick(x, y, options) which wraps click with clickCount: 2, and wheel(deltaX, deltaY) for scroll wheel simulation.
  • Touchscreen implements api.Touchscreen with a single tap(x, y) method.

Usage

Use these classes to simulate low-level input events when high-level Playwright methods like page.click() or locator.fill() are insufficient. Access them via page.keyboard, page.mouse, and page.touchscreen.

Code Reference

Source Location

Signature

export class Keyboard implements api.Keyboard {
  constructor(page: Page);
  async down(key: string): Promise<void>;
  async up(key: string): Promise<void>;
  async insertText(text: string): Promise<void>;
  async type(text: string, options?: { delay?: number }): Promise<void>;
  async press(key: string, options?: { delay?: number }): Promise<void>;
}

export class Mouse implements api.Mouse {
  constructor(page: Page);
  async move(x: number, y: number, options?: { steps?: number }): Promise<void>;
  async down(options?: { button?: string; clickCount?: number }): Promise<void>;
  async up(options?: { button?: string; clickCount?: number }): Promise<void>;
  async click(x: number, y: number, options?: MouseClickOptions): Promise<void>;
  async dblclick(x: number, y: number, options?: Omit<MouseClickOptions, 'clickCount'>): Promise<void>;
  async wheel(deltaX: number, deltaY: number): Promise<void>;
}

export class Touchscreen implements api.Touchscreen {
  constructor(page: Page);
  async tap(x: number, y: number): Promise<void>;
}

Import

import { Keyboard, Mouse, Touchscreen } from 'playwright-core/src/client/input';

I/O Contract

Inputs

Name Type Required Description
page Page Yes The page to send input events to (constructor parameter)
key string Yes Key name for keyboard operations (e.g., 'Enter', 'a', 'Control')
text string Yes Text string for type() and insertText()
x, y number Yes Coordinates for mouse and touchscreen operations
options.delay number No Delay between key events in milliseconds
options.steps number No Number of intermediate mouse move events
deltaX, deltaY number Yes Scroll amounts for wheel()

Outputs

Name Type Description
All methods Promise<void> All input methods return void promises upon completion

Usage Examples

// Keyboard operations
await page.keyboard.type('Hello World', { delay: 100 });
await page.keyboard.press('Enter');
await page.keyboard.down('Shift');
await page.keyboard.press('ArrowLeft');
await page.keyboard.up('Shift');

// Mouse operations
await page.mouse.move(100, 200);
await page.mouse.click(100, 200, { button: 'left' });
await page.mouse.dblclick(100, 200);
await page.mouse.wheel(0, 300); // Scroll down

// Touchscreen
await page.touchscreen.tap(100, 200);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment