press_key
Press hardware or software keys on Android devices to navigate interfaces, control volume, power, and access functions like home, back, menu, camera, and search.
Instructions
Press a hardware/software key on the Android device. Common keycodes: HOME, BACK, MENU, ENTER, VOLUME_UP, VOLUME_DOWN, POWER, DEL, TAB, SPACE, APP_SWITCH, SEARCH, CAMERA.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keycode | Yes | Android keycode name (e.g. HOME, BACK, ENTER, VOLUME_UP) or numeric code | |
| device_id | No | Device serial number |
Implementation Reference
- src/adb/input-controller.ts:148-158 (handler)The core handler function that executes the ADB keyevent command.
export async function pressKey(keycode: string, deviceId?: string): Promise<string> { const resolved = await deviceManager.resolveDeviceId(deviceId); deviceManager.checkRateLimit(resolved); const validatedKeycode = validateKeycode(keycode); await adbShell(['input', 'keyevent', validatedKeycode], resolved); deviceManager.touchSession(resolved); log.info('Key press performed', { keycode: validatedKeycode, deviceId: resolved }); return validatedKeycode; } - src/controllers/input-tools.ts:230-260 (registration)MCP tool registration and wrapper for the 'press_key' tool.
'press_key', { description: 'Press a hardware/software key on the Android device. Common keycodes: HOME, BACK, MENU, ENTER, VOLUME_UP, VOLUME_DOWN, POWER, DEL, TAB, SPACE, APP_SWITCH, SEARCH, CAMERA.', inputSchema: { keycode: z.string().describe('Android keycode name (e.g. HOME, BACK, ENTER, VOLUME_UP) or numeric code'), device_id: z.string().optional().describe('Device serial number'), }, }, async ({ keycode, device_id }) => { return await metrics.measure('press_key', device_id || 'default', async () => { const resolved = await deviceManager.resolveDeviceId(device_id); const execCtx = executionEngine.preExecutionCheck('press_key', { keycode }, resolved); if (!execCtx.allowed) { return { content: [{ type: 'text' as const, text: JSON.stringify({ success: false, blocked: true, reason: execCtx.blockReason, _context: execCtx.recentContext }, null, 2), }], }; } const preHash = await capturePreActionState(resolved); const result = await pressKey(keycode, device_id); invalidateCaches(resolved); const verification = await verifyAction('press_key', resolved, preHash); return buildVerifiedResponse({ pressed_key: result }, execCtx, verification); }); } );