pressKey
Press hardware keys on mobile devices for automation testing. Simulate actions like home, back, menu, power, and volume controls on Android and iOS platforms.
Instructions
Press a hardware key on the device (Maestro equivalent of pressButton)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | The key to press | |
| platform | Yes | Platform of the device |
Implementation Reference
- src/server/interactionTools.ts:548-557 (handler)The pressKey tool handler function. Creates a PressButton instance and executes it with the provided key, then returns a formatted JSON response.const pressKeyHandler = async (device: BootedDevice, args: PressKeyArgs, progress?: ProgressCallback) => { const pressButton = new PressButton(device); const result = await pressButton.execute(args.key, progress); return createJSONToolResponse({ message: `Pressed key ${args.key}`, observation: result.observation, ...result }); };
- Zod schema defining the input arguments for the pressKey tool: key (enum of hardware keys) and platform.export const pressKeySchema = z.object({ key: z.enum(["home", "back", "menu", "power", "volume_up", "volume_down", "recent"]) .describe("The key to press"), platform: z.enum(["android", "ios"]).describe("Platform of the device") });
- src/server/interactionTools.ts:715-722 (registration)Registration of the pressKey tool using ToolRegistry.registerDeviceAware, providing name, description, schema, handler, and progress support.ToolRegistry.registerDeviceAware( "pressKey", "Press a hardware key on the device (Maestro equivalent of pressButton)", pressKeySchema, pressKeyHandler, true // Supports progress notifications );
- src/server/interactionTools.ts:41-44 (schema)TypeScript interface defining the PressKeyArgs type used by the handler.export interface PressKeyArgs { key: "home" | "back" | "menu" | "power" | "volume_up" | "volume_down" | "recent"; platform: Platform; }