Skip to main content
Glama

android_send_key_event

Simulate hardware button presses on Android devices, such as HOME, BACK, or ENTER, for automated testing and remote control.

Instructions

Send a key event to the Android device (e.g., KEYEVENT_HOME, KEYEVENT_BACK, KEYEVENT_ENTER)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keyCodeYesKey event code (e.g., KEYEVENT_HOME, KEYEVENT_BACK, KEYEVENT_ENTER, 3 for HOME, 4 for BACK). Can be key name or numeric code.
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • The main handler function for the 'android_send_key_event' tool. It extracts arguments, calls the ADB wrapper's sendKeyEvent method, and returns a success message or throws an error.
    export async function handleSendKeyEvent(adb: ADBWrapper, args: SendKeyEventArgs): Promise<{ content: Array<{ type: string; text: string }> }> { const { keyCode, deviceSerial } = args; try { await adb.sendKeyEvent(keyCode, deviceSerial); return { content: [ { type: 'text', text: `Key event sent: ${keyCode}`, }, ], }; } catch (error) { throw new Error(`Failed to send key event: ${error instanceof Error ? error.message : String(error)}`); } }
  • The input schema and tool metadata definition for 'android_send_key_event' used in tool listing and validation.
    { name: 'android_send_key_event', description: 'Send a key event to the Android device (e.g., KEYEVENT_HOME, KEYEVENT_BACK, KEYEVENT_ENTER)', inputSchema: { type: 'object', properties: { keyCode: { type: 'string', description: 'Key event code (e.g., KEYEVENT_HOME, KEYEVENT_BACK, KEYEVENT_ENTER, 3 for HOME, 4 for BACK). Can be key name or numeric code.', }, deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, required: ['keyCode'], }, },
  • src/index.ts:502-503 (registration)
    The switch case registration that dispatches calls to the 'android_send_key_event' handler function.
    case 'android_send_key_event': return await handleSendKeyEvent(this.adb, args as any);
  • Supporting utility method in ADBWrapper class that executes the actual ADB 'shell input keyevent' command to send the key event to the device.
    async sendKeyEvent(keyCode: string, deviceSerial?: string): Promise<void> { const device = await this.getTargetDevice(deviceSerial); await this.exec(['shell', 'input', 'keyevent', keyCode], device); }
  • TypeScript interface defining the input arguments for the send key event handler.
    interface SendKeyEventArgs { keyCode: string; deviceSerial?: 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/jduartedj/android-mcp-server'

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