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
| Name | Required | Description | Default |
|---|---|---|---|
| x | Yes | X coordinate | |
| y | Yes | Y coordinate | |
| duration | No | Press duration in milliseconds (default: 1000) | |
| device_id | No | Device serial number |
Implementation Reference
- src/adb/input-controller.ts:84-107 (handler)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; } - src/controllers/input-tools.ts:139-158 (registration)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); });