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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but lacks behavioral details. It doesn't disclose effects (e.g., whether it simulates physical key presses, requires device connectivity, or has rate limits), leaving the agent to infer behavior from the action 'Send'.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose and provides relevant examples without unnecessary elaboration. Every word contributes to understanding the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 2 parameters, 100% schema coverage, and no output schema, the description is adequate but incomplete. It covers the basic purpose but lacks details on behavioral traits (e.g., device state requirements or error handling), which are important given the absence of annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents keyCode and deviceSerial parameters. The description adds minimal value by listing example key codes (KEYEVENT_HOME, KEYEVENT_BACK, KEYEVENT_ENTER), which aligns with but doesn't significantly expand on schema details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Send a key event') and target ('Android device'), with examples like KEYEVENT_HOME and KEYEVENT_BACK. It distinguishes from siblings like android_input_text (for text) and android_touch (for touch gestures), but doesn't explicitly contrast them.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives is provided. For example, it doesn't specify when to use android_send_key_event over android_input_text for Enter key events or android_touch for navigation, leaving usage context implied rather than explicit.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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