press-key
Simulate key presses on web elements using specified selectors. Integrates with AdsPower LocalAPI MCP Server for automated browser interactions, enabling precise control within browser profiles.
Instructions
Press the key
Input 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 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"key": {
"description": "The key to press, eg: \"Enter\"",
"type": "string"
},
"selector": {
"description": "The selector of the element to press the key, find from the page source code",
"type": "string"
}
},
"required": [
"key"
],
"type": "object"
}
Implementation Reference
- src/handlers/automation.ts:123-130 (handler)The main handler function for the 'press-key' tool. It checks browser connection, optionally waits for and focuses a selector, presses the specified key using Puppeteer's keyboard.press, and returns a 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 input validation of the 'press-key' tool: requires 'key' (string, e.g., 'Enter'), 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 with the MCP server, providing name, description, input schema, and wrapped handler from automationHandlers.server.tool('press-key', 'Press the key', schemas.pressKeySchema.shape, wrapHandler(automationHandlers.pressKey));