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 Server Input

From Leeroopedia
Knowledge Sources
Domains Input Simulation, Keyboard Mouse Touch
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for dispatching keyboard, mouse, and touchscreen input events on the server side provided by the Playwright library.

Description

The `input.ts` module provides the `Keyboard`, `Mouse`, and `Touchscreen` classes that abstract input event dispatching across all browser engines. The `Keyboard` class handles key press/release events, key combinations, modifier tracking (Alt, Control, Meta, Shift), and text insertion, using a `RawKeyboard` interface for browser-specific implementations. The `Mouse` class manages mouse movement, clicks (single, double, triple), button press/release, wheel scrolling, and drag operations, while tracking current position and pressed buttons. The `Touchscreen` class handles tap events. All classes maintain internal state (pressed keys, mouse position, modifiers) and delegate to browser-specific `Raw*` interfaces. The `KeyDescription` type provides key metadata including keyCodes, text values, and location codes.

Usage

Use this module when simulating user input in the Playwright server. It provides the cross-browser input abstraction used by all page-level interaction methods.

Code Reference

Source Location

Signature

export interface RawKeyboard {
  keydown(progress: Progress, modifiers: Set<types.KeyboardModifier>, keyName: string, description: KeyDescription, autoRepeat: boolean): Promise<void>;
  keyup(progress: Progress, modifiers: Set<types.KeyboardModifier>, keyName: string, description: KeyDescription): Promise<void>;
  sendText(progress: Progress, text: string): Promise<void>;
}

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

export class Mouse {
  constructor(raw: RawMouse, page: Page);
  async move(progress: Progress, x: number, y: number, options?: { steps?: number }): Promise<void>;
  async click(progress: Progress, x: number, y: number, options?: types.MouseClickOptions): Promise<void>;
  async dblclick(progress: Progress, x: number, y: number, options?: types.MouseMultiClickOptions): Promise<void>;
  async wheel(progress: Progress, deltaX: number, deltaY: number): Promise<void>;
}

export class Touchscreen {
  constructor(raw: RawTouchscreen, page: Page);
  async tap(progress: Progress, x: number, y: number): Promise<void>;
}

Import

import { Keyboard, Mouse, Touchscreen } from '../server/input';
import type { RawKeyboard, RawMouse, RawTouchscreen, KeyDescription } from '../server/input';

I/O Contract

Inputs

Name Type Required Description
raw RawKeyboard / RawMouse / RawTouchscreen Yes Browser-specific raw input implementation
page Page Yes Page to dispatch input events on
progress Progress Yes Progress tracker for timeout and cancellation
key string Yes Key name for keyboard operations (e.g., 'Enter', 'a')
x, y number Yes Coordinates for mouse/touch operations

Outputs

Name Type Description
void void Input events are dispatched as side effects
modifiers Set<KeyboardModifier> Currently pressed modifier keys (internal state)

Usage Examples

// Created internally by Page
const keyboard = new Keyboard(rawKeyboard, page);
const mouse = new Mouse(rawMouse, page);
const touchscreen = new Touchscreen(rawTouchscreen, page);

// Keyboard input
await keyboard.type(progress, 'Hello World', { delay: 100 });
await keyboard.press(progress, 'Enter');

// Mouse input
await mouse.click(progress, 100, 200, { button: 'left' });
await mouse.wheel(progress, 0, -100);

// Touch input
await touchscreen.tap(progress, 150, 300);

Related Pages

Page Connections

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