pressKey
Simulate keyboard key presses in browser automation workflows. Specify the key (e.g., 'Enter', 'Escape') to execute actions like form submissions or navigation, enhancing interaction efficiency.
Instructions
Press a key on the keyboard
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key to press (e.g., 'Enter', 'Escape', 'ArrowDown', etc.) |
Implementation Reference
- src/controllers/playwright.ts:666-678 (handler)The core handler function that executes the pressKey tool logic using Playwright's page.keyboard.press(key) method.async pressKey(key: string): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Pressing key', { key }); await this.state.page.keyboard.press(key); this.log('Key press complete'); } catch (error: any) { console.error('Press key error:', error); throw new BrowserError('Failed to press key', 'Check if the key name is valid'); } }
- src/server.ts:312-325 (schema)The input schema definition for the pressKey tool, specifying the required 'key' parameter.const PRESS_KEY_TOOL: Tool = { name: "pressKey", description: "Press a key on the keyboard", inputSchema: { type: "object", properties: { key: { type: "string", description: "Key to press (e.g., 'Enter', 'Escape', 'ArrowDown', etc.)" } }, required: ["key"] } };
- src/server.ts:834-845 (registration)The registration and dispatch logic in the MCP callTool request handler that invokes the pressKey controller method.case 'pressKey': { if (!args.key) { return { content: [{ type: "text", text: "Key is required" }], isError: true }; } await playwrightController.pressKey(args.key as string); return { content: [{ type: "text", text: "Key pressed successfully" }] }; }