Skip to main content
Glama

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
NameRequiredDescriptionDefault
deviceIdNoDevice ID (optional)
keyCodeYesKey code to press (e.g., "BACK", "HOME", "MENU", or numeric code)

Implementation Reference

  • 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' }; } }
  • 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));

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/richard0913/adb-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server