adb_press_key
Simulate key presses on Android devices using the ADB MCP Server. Specify the key code (e.g., BACK, HOME) to automate device interactions for testing or remote management.
Instructions
Press a key on the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | Device ID (optional) | |
| keyCode | Yes | Key code to press (e.g., "BACK", "HOME", "MENU", or numeric code) |
Implementation Reference
- src/tools/screen.ts:241-278 (handler)The main handler function that executes the ADB command to press a key on the device.async pressKey(keyCode: string | number, deviceId?: string) { try { const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot press key - device is not connected' }; } const command = `shell input keyevent ${keyCode}`; const result = await this.adbClient.executeCommand(command, deviceId); if (!result.success) { return { success: false, error: result.error, message: 'Failed to press key' }; } return { success: true, data: { keyCode, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: `Pressed key: ${keyCode}` }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to press key' }; } }
- src/index.ts:182-199 (schema)Input schema definition for the adb_press_key tool.{ name: 'adb_press_key', description: 'Press a key on the device', inputSchema: { type: 'object', properties: { keyCode: { type: ['string', 'number'], description: 'Key code to press (e.g., "BACK", "HOME", "MENU", or numeric code)', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: ['keyCode'], }, },
- src/index.ts:449-450 (registration)Tool registration in the switch statement dispatching to the handler.case 'adb_press_key': return await this.handleToolCall(this.screenTools.pressKey(args?.keyCode as string | number, args?.deviceId as string));