Skip to content

Input

Injecting input events on a connected device (adb shell input): taps, swipes, text, and key events.

input_text

Type literal text into the focused input field: adb shell input text.

The text goes to whatever view currently has input focus; if nothing is focused, Android drops the keystrokes and this tool cannot tell. Spaces are handled; some punctuation and non-ASCII characters may not inject reliably — that's an Android input text limitation, not a bug here.

Parameters:

Name Type Description Default
serial str

The target device's adb serial (see list_connected_devices).

required
text str

The string to type. Must not be empty.

required
display_id int | None

Inject on one specific display (-d, see list_displays).

None

Returns:

Type Description
TextInputResult

The serial, the text, display_id, success (always True — see Error handling), and the raw (usually empty) input output.

Error handling

An empty text is rejected before any device round-trip (INVALID_ARGUMENT). An unknown serial or unresponsive adb binary raises DEVICE_NOT_FOUND/ADB_UNAVAILABLE; a permission rejection raises PERMISSION_DENIED; any other failure raises BACKEND_ERROR.

Example

Called with serial="emulator-5554", text="hello world". A typical response:

{
  "status": "success",
  "message": "Typed 'hello world' on emulator-5554.",
  "data": {
    "serial": "emulator-5554",
    "text": "hello world",
    "display_id": null,
    "success": true,
    "output": ""
  },
  "error": null
}

press_key

Inject one Android key event: adb shell input keyevent.

key is a typed name from a curated set (HOME, BACK, ENTER, DPAD_, VOLUME_, WAKEUP, MEDIA_PLAY_PAUSE, …) — arbitrary keycodes aren't accepted. It's mapped to the matching KEYCODE_<name>.

Parameters:

Name Type Description Default
serial str

The target device's adb serial (see list_connected_devices).

required
key PressableKey

The key to press. One of the names in the input schema's enum (e.g. "BACK", "HOME", "ENTER", "DPAD_DOWN", "WAKEUP").

required
display_id int | None

Inject on one specific display (-d, see list_displays).

None

Returns:

Type Description
PressKeyResult

The serial, the key name, the resolved keycode ("KEYCODE_"), display_id, success (always True — see Error handling), and the raw (usually empty) input output.

Error handling

An unknown key is rejected by the tool's input schema (and again in the service) before any device round-trip. An unknown serial or unresponsive adb binary raises DEVICE_NOT_FOUND/ADB_UNAVAILABLE; a permission rejection raises PERMISSION_DENIED; any other failure raises BACKEND_ERROR.

Example

Called with serial="emulator-5554", key="BACK". A typical response:

{
  "status": "success",
  "message": "Pressed BACK on emulator-5554.",
  "data": {
    "serial": "emulator-5554",
    "key": "BACK",
    "keycode": "KEYCODE_BACK",
    "display_id": null,
    "success": true,
    "output": ""
  },
  "error": null
}

swipe

Inject a swipe gesture between two points: adb shell input swipe.

Parameters:

Name Type Description Default
serial str

The target device's adb serial (see list_connected_devices).

required
x1 int

Start X, pixels from the left edge. Non-negative.

required
y1 int

Start Y, pixels from the top edge. Non-negative.

required
x2 int

End X, pixels from the left edge. Non-negative.

required
y2 int

End Y, pixels from the top edge. Non-negative.

required
duration_ms int | None

How long the swipe takes, in milliseconds (non-negative). Omit to use input's default. A longer duration reads as a drag / fling depending on distance.

None
display_id int | None

Inject on one specific display (-d, see list_displays).

None

Returns:

Type Description
SwipeResult

The serial, the four coordinates, duration_ms and display_id used, success (always True — see Error handling), and the raw (usually empty) input output.

Error handling

A negative coordinate or duration is rejected before any device round-trip (INVALID_ARGUMENT). An unknown serial or unresponsive adb binary raises DEVICE_NOT_FOUND/ADB_UNAVAILABLE; a permission rejection raises PERMISSION_DENIED; any other failure raises BACKEND_ERROR.

Example

Called with serial="emulator-5554", x1=500, y1=1500, x2=500, y2=300, duration_ms=250. A typical response:

{
  "status": "success",
  "message": "Swiped (500,1500)→(500,300) on emulator-5554 over 250ms.",
  "data": {
    "serial": "emulator-5554",
    "x1": 500, "y1": 1500, "x2": 500, "y2": 300,
    "duration_ms": 250, "display_id": null,
    "success": true, "output": ""
  },
  "error": null
}

tap

Inject a single touch/tap event on a device: adb shell input tap.

Models one specific input event (a tap) rather than accepting a raw input command string — see the module docs for why this server never exposes arbitrary shell arguments. For other input events, use swipe, input_text, or press_key.

Parameters:

Name Type Description Default
serial str

The target device's adb serial (see list_connected_devices).

required
x int

The horizontal coordinate to tap, in pixels from the screen's left edge. Must be a non-negative integer.

required
y int

The vertical coordinate to tap, in pixels from the screen's top edge. Must be a non-negative integer.

required
display_id int | None

Inject the tap on one specific display (-d, see list_displays) on a multi-display device. Omit to use the default display.

None

Returns:

Type Description
TapResult

The serial, x, y, and display_id the tap was injected with, plus success (always True — see Error handling) and the raw (usually empty) input output.

Error handling

x or y being negative is rejected before any device round-trip (INVALID_ARGUMENT). Beyond that: an unknown serial or unresponsive adb binary raises DEVICE_NOT_FOUND/ADB_UNAVAILABLE; a permission rejection raises PERMISSION_DENIED; any other input/adb failure raises a generic BACKEND_ERROR.

Example

Called with serial="emulator-5554", x=500, y=800. A typical response:

{
  "status": "success",
  "message": "Tapped (500, 800) on emulator-5554.",
  "data": {
    "serial": "emulator-5554",
    "x": 500,
    "y": 800,
    "display_id": null,
    "success": true,
    "output": ""
  },
  "error": null
}