Skip to main content
Glama

press_key

Press hardware or software keys on Android devices to navigate interfaces, control volume, power, and access functions like home, back, menu, camera, and search.

Instructions

Press a hardware/software key on the Android device. Common keycodes: HOME, BACK, MENU, ENTER, VOLUME_UP, VOLUME_DOWN, POWER, DEL, TAB, SPACE, APP_SWITCH, SEARCH, CAMERA.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keycodeYesAndroid keycode name (e.g. HOME, BACK, ENTER, VOLUME_UP) or numeric code
device_idNoDevice serial number

Implementation Reference

  • The core handler function that executes the ADB keyevent command.
    export async function pressKey(keycode: string, deviceId?: string): Promise<string> {
      const resolved = await deviceManager.resolveDeviceId(deviceId);
      deviceManager.checkRateLimit(resolved);
    
      const validatedKeycode = validateKeycode(keycode);
      await adbShell(['input', 'keyevent', validatedKeycode], resolved);
    
      deviceManager.touchSession(resolved);
      log.info('Key press performed', { keycode: validatedKeycode, deviceId: resolved });
      return validatedKeycode;
    }
  • MCP tool registration and wrapper for the 'press_key' tool.
      'press_key',
      {
        description: 'Press a hardware/software key on the Android device. Common keycodes: HOME, BACK, MENU, ENTER, VOLUME_UP, VOLUME_DOWN, POWER, DEL, TAB, SPACE, APP_SWITCH, SEARCH, CAMERA.',
        inputSchema: {
          keycode: z.string().describe('Android keycode name (e.g. HOME, BACK, ENTER, VOLUME_UP) or numeric code'),
          device_id: z.string().optional().describe('Device serial number'),
        },
      },
      async ({ keycode, device_id }) => {
        return await metrics.measure('press_key', device_id || 'default', async () => {
          const resolved = await deviceManager.resolveDeviceId(device_id);
          const execCtx = executionEngine.preExecutionCheck('press_key', { keycode }, resolved);
    
          if (!execCtx.allowed) {
            return {
              content: [{
                type: 'text' as const,
                text: JSON.stringify({ success: false, blocked: true, reason: execCtx.blockReason, _context: execCtx.recentContext }, null, 2),
              }],
            };
          }
    
          const preHash = await capturePreActionState(resolved);
          const result = await pressKey(keycode, device_id);
          invalidateCaches(resolved);
          const verification = await verifyAction('press_key', resolved, preHash);
    
          return buildVerifiedResponse({ pressed_key: result }, execCtx, verification);
        });
      }
    );
Behavior2/5

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

No annotations provided, so description carries full burden. States the action but fails to disclose mutation effects (e.g., HOME backgrounds app, POWER locks screen), error behavior for invalid keycodes, or that device_id omission likely uses default device.

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?

Single sentence for action definition followed by targeted example list. No redundancy or filler; every word earns its place. Efficiently front-loaded.

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?

Adequate for a 2-parameter tool with no output schema, covering basic functionality. However, gaps remain regarding optional parameter defaults (device_id), side effects of specific keys, and error handling scenarios.

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 coverage is 100% with keycode already documented as accepting names or numeric codes. Description expands the example list beyond the schema's examples, adding some value, but baseline 3 is appropriate given schema completeness.

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

Purpose5/5

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

Description clearly states the specific action (press) and target (hardware/software key) with concrete examples (HOME, BACK, POWER) that distinguish it from siblings like tap, click_element, or input_text.

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

Usage Guidelines3/5

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

Provides implied usage through examples of hardware keys, but lacks explicit guidance on when to choose this over tap/click_element for navigation or input_text for text entry. No prerequisites or error conditions mentioned.

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/divineDev-dotcom/android_mcp'

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