Skip to main content
Glama

long_press

Simulate long press gestures on Android screens to access context menus, initiate drag actions, or select UI elements by specifying coordinates and duration.

Instructions

Long press at specific coordinates on the Android screen. Useful for context menus, drag initiation, or selection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
xYesX coordinate
yYesY coordinate
durationNoPress duration in milliseconds (default: 1000)
device_idNoDevice serial number

Implementation Reference

  • The core implementation of the long_press tool, which performs an ADB swipe operation for a specific duration to simulate a long press.
    export async function longPress(
      x: number, y: number,
      durationMs: number = 1000,
      deviceId?: string
    ): Promise<{ x: number; y: number }> {
      const resolved = await deviceManager.resolveDeviceId(deviceId);
      deviceManager.checkRateLimit(resolved);
    
      const coords = await normalizeCoordinates(x, y, resolved);
      validateCoordinate(coords.x, 'x');
      validateCoordinate(coords.y, 'y');
    
      // Long press = swipe to same point with long duration
      await adbShell([
        'input', 'swipe',
        String(coords.x), String(coords.y),
        String(coords.x), String(coords.y),
        String(Math.round(durationMs)),
      ], resolved);
    
      deviceManager.touchSession(resolved);
      log.info('Long press performed', { x: coords.x, y: coords.y, durationMs, deviceId: resolved });
      return coords;
    }
  • The MCP tool registration and handler entry point, which invokes the longPress function from the input-controller.
    return await metrics.measure('long_press', device_id || 'default', async () => {
      const resolved = await deviceManager.resolveDeviceId(device_id);
      const execCtx = executionEngine.preExecutionCheck('long_press', { x, y, duration }, 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 longPress(x, y, duration, device_id);
      invalidateCaches(resolved);
      const verification = await verifyAction('long_press', resolved, preHash);
    
      return buildVerifiedResponse({ pressed: result }, execCtx, verification);
    });

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