input_keyevent
Simulate key events (BACK, HOME, ENTER, DELETE) on Android devices via ADB for automation and testing, enabling device control and input simulation.
Instructions
Send key events (BACK, HOME, ENTER, DELETE)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Key event to send |
Implementation Reference
- src/tools/handlers.ts:138-166 (handler)The main handler function for the 'input_keyevent' tool. Maps the key to an ADB keycode, sends the keyevent command via adb shell input, captures updated UI hierarchy, and returns confirmation with UI dump.input_keyevent: async (args: any) => { const { key } = args as { key: string }; const keyCodeMap = { BACK: '4', HOME: '3', ENTER: '66', DELETE: '67', }; const keyCode = keyCodeMap[key as keyof typeof keyCodeMap]; if (!keyCode) { throw new McpError(ErrorCode.InvalidParams, `Invalid key: ${key}`); } await executeCommand(`adb shell input keyevent ${keyCode}`); const uiContent = await captureUIContent(false); return { content: [ { type: 'text', text: `Key event sent: ${key} (${keyCode})`, }, ...uiContent, ], }; },
- src/tools/definitions.ts:70-84 (schema)Input schema definition for the 'input_keyevent' tool, specifying the required 'key' parameter with enum values.{ name: 'input_keyevent', description: 'Send key events (BACK, HOME, ENTER, DELETE)', inputSchema: { type: 'object', properties: { key: { type: 'string', enum: ['BACK', 'HOME', 'ENTER', 'DELETE'], description: 'Key event to send', }, }, required: ['key'], }, },
- src/index.ts:26-30 (registration)Registers the ListToolsRequestSchema handler, which returns the toolDefinitions array including the 'input_keyevent' schema.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolDefinitions, }; });
- src/index.ts:32-46 (registration)Registers the CallToolRequestSchema handler, which dispatches execution to toolHandlers[name] for 'input_keyevent'.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const handler = toolHandlers[name as keyof typeof toolHandlers]; if (!handler) { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } return await handler(args); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${errorMessage}`); } });