press-key
Simulate keyboard key presses on web elements to automate browser interactions within AdsPower profiles.
Instructions
Press the key
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The key to press, eg: "Enter" | |
| selector | No | The selector of the element to press the key, find from the page source code |
Implementation Reference
- src/handlers/automation.ts:123-131 (handler)The pressKey handler function that checks connection, optionally focuses a selector, presses the specified key using Puppeteer's keyboard, and returns success message.async pressKey({ key, selector }: PressKeyParams) { browser.checkConnected(); if (selector) { await browser.pageInstance!.waitForSelector(selector); await browser.pageInstance!.focus(selector); } await browser.pageInstance!.keyboard.press(key); return `Pressed key: ${key} successfully`; },
- src/types/schemas.ts:204-207 (schema)Zod schema for 'press-key' tool parameters: required 'key' string and optional 'selector' string.pressKeySchema: z.object({ key: z.string().describe('The key to press, eg: "Enter"'), selector: z.string().optional().describe('The selector of the element to press the key, find from the page source code') }).strict(),
- src/utils/toolRegister.ts:83-84 (registration)Registers the 'press-key' tool on the MCP server with description, input schema, and wrapped automationHandlers.pressKey handler.server.tool('press-key', 'Press the key', schemas.pressKeySchema.shape, wrapHandler(automationHandlers.pressKey));