GuidePublished: 8 min read

Simulate Taps, Swipes, Text and Key Presses With adb shell input

Use adb shell input tap, swipe, text and keyevent to drive an Android device from your computer, with a keycode table, coordinate tips and repro scripts.

adb shell input lets you simulate taps, swipes, text and key presses on an Android device without touching it: input tap 540 1200 taps a point, input swipe drags between two points, input text types into the focused field and input keyevent 4 presses Back. They are the backbone of quick repro scripts and demo automation. This guide collects the forms that work reliably, the keycodes you will actually use, and ways to find coordinates. If you mostly need to click around, the live screen in ADBKit covers that with a mouse; the commands below are for everything else.

Note: All examples assume one device connected with USB debugging on. With several devices, add -s <serial> after adb. Commands are shown as adb shell ... for the command line; inside an interactive shell or ADBKit's Shell drawer, drop the adb shell prefix.

Taps and swipes with input tap and input swipe

input tap takes X and Y in screen pixels, measured from the top-left corner in the current orientation:

adb shell input tap 540 1200

input swipe takes a start point, an end point and an optional duration in milliseconds. A short swipe scrolls, a long one drags slowly:

adb shell input swipe 540 1600 540 400 300

There is no dedicated long-press command, but a swipe that starts and ends at the same point with a long duration does the job:

adb shell input swipe 540 1200 540 1200 1000

You can also name the input source, which helps on devices with a stylus: input touchscreen tap 540 1200. Multi-touch gestures such as pinch-to-zoom are not possible with input; those need a UI test framework or sendevent.

Finding the coordinates to tap

The trick is knowing where to tap. Four approaches, from easiest to most precise:

  1. Pointer location. In Developer options, turn on Pointer location; a bar at the top of the screen shows the X/Y of your finger in real time. Android Developer options for testing explains this and the related Show taps overlay. From the command line: adb shell settings put system pointer_location 1.
  2. Screenshot pixels. Take a screenshot with adb exec-out screencap -p > s.png, open it in an image editor and read the pixel position of the button. Screenshot pixels are screen pixels.
  3. getevent. adb shell getevent -l prints raw touch events as you touch the screen. The ABS_MT_POSITION_X/Y values use the touch panel's own range, which may differ from the screen resolution.
  4. UI dump. adb shell uiautomator dump writes an XML file with the bounds of every view, the most robust way to script against a specific button.

Coordinates depend on resolution and orientation. Check with adb shell wm size, and use percentages of width and height if a script must run on more than one device.

Typing with input text

input text sends a string to the focused field. The catch is that the device shell parses the string, so spaces and special characters need care. Replace spaces with %s and wrap the whole thing in single quotes:

adb shell input text 'hello%sworld'

Characters that mean something to the shell, such as &, |, <, >, (, ), ; and $, must be backslash-escaped even inside quotes, because the string is interpreted twice. Filling a login form looks like this:

adb shell input text 'tester@example.com'
adb shell input keyevent 61
adb shell input text 'Pa\$\$word1'
adb shell input keyevent 66

Keycode 61 is Tab and 66 is Enter. input text only handles ASCII reliably; accented letters, Vietnamese diacritics, emoji and CJK characters are usually dropped or garbled. For non-ASCII text, paste from the clipboard, use a test keyboard app such as ADB Keyboard, or use your app's own test hooks.

Key presses with input keyevent

input keyevent takes a numeric keycode or its KEYCODE_ name. Both lines below press Home:

adb shell input keyevent 3
adb shell input keyevent KEYCODE_HOME

Add --longpress for a long press, for example input keyevent --longpress 26 to open the power menu. You can also send several keys in one call: input keyevent 4 4 3 presses Back twice and then Home. These are the keycodes most testers reach for:

CodeNameWhat it does
3HOMEGo to the home screen
4BACKBack
187APP_SWITCHRecent apps
82MENULegacy menu key; wakes some lock screens
26POWERToggle the screen; long press for the power menu
223SLEEPTurn the screen off
224WAKEUPTurn the screen on
24 / 25VOLUME_UP / VOLUME_DOWNVolume
164VOLUME_MUTEMute
85MEDIA_PLAY_PAUSEPlay or pause media
66ENTERSubmit or new line
67DELBackspace
61TABMove to the next field
111ESCAPEClose dialogs on some apps
277 / 278 / 279CUT / COPY / PASTEClipboard actions in the focused field
19 to 22DPAD_UP/DOWN/LEFT/RIGHTNavigate focus, useful on TV and for accessibility checks

A few non-input commands pair well with the above.

Wake and unlock

A fresh test run usually starts on a dark lock screen. Wake the device, then swipe up to dismiss a lock screen without a PIN:

adb shell input keyevent KEYCODE_WAKEUP
adb shell input swipe 540 1800 540 600 200

With a PIN, follow up with input text 1234 and input keyevent 66. A dedicated test device without a lock is simpler and safer.

adb shell am start -a android.intent.action.VIEW -d "https://example.com/item/42"
adb shell am start -n com.example.app/.MainActivity
adb shell am force-stop com.example.app
adb shell cmd statusbar expand-notifications
adb shell cmd statusbar collapse

am start with VIEW is the quickest way to test deep links and App Links; am force-stop kills the app so the next launch is cold.

Screen size and density

Layout bugs often depend on screen size. Fake a smaller or denser display without another device:

adb shell wm size 720x1280
adb shell wm density 320
adb shell wm size reset
adb shell wm density reset

Remember that input tap coordinates change when you override the size.

Scripting a repro loop

Chaining these commands in a shell script turns a flaky bug into one you can hit a hundred times. This loop opens a screen via deep link, scrolls, goes back and repeats:

#!/bin/bash
for i in $(seq 1 50); do
  adb shell am start -a android.intent.action.VIEW -d "myapp://orders/42"
  sleep 2
  adb shell input swipe 540 1600 540 400 300
  sleep 1
  adb shell input keyevent 4
  sleep 1
done

Use sleep generously: input returns before the UI has finished reacting, and a tap that lands mid-transition is the most common cause of a flaky script. Tail adb logcat in a second terminal to catch the crash.

Warning: input commands are real input. A script that taps the wrong coordinates on a personal phone can delete messages or send a payment. Run repro loops on a test device, and check wm size first.

Doing it with a mouse in ADBKit

ADBKit shows the live device screen in Chrome or Edge over WebUSB, and most of the commands above map to a mouse or a button in the toolbar:

CommandADBKit equivalent
input tap x yClick on the mirrored screen
input swipeClick and drag on the screen
input keyevent 4 / 3 / 187Back, Home and App Switcher buttons
input keyevent 24 / 25Volume up and down buttons
wm size for a different orientationRotation button
  1. Open ADBKit, connect the phone over USB and click Connect device, then tap Allow on the phone.
  2. Start the live screen view; pick 720p in the stream quality setting if the connection is slow.
  3. Click to tap and drag to swipe. Turn on Show taps in Developer options if you want your clicks visible in a Screen Record capture.
  4. For input text, am start, wm size or anything not on the toolbar, open the Shell drawer and type the command without the adb shell prefix.

Typing with your keyboard directly into the mirrored screen is not supported, so use the Shell drawer with input text for that. Only one program can hold the USB connection, so close adb sessions or scrcpy if ADBKit fails to connect. For the rest of the command family, see the ADB commands cheat sheet and control Android from your browser.