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>afteradb. Commands are shown asadb shell ...for the command line; inside an interactive shell or ADBKit's Shell drawer, drop theadb shellprefix.
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 1200input 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 300There 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 1000You 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:
- 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. - 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. - getevent.
adb shell getevent -lprints raw touch events as you touch the screen. TheABS_MT_POSITION_X/Yvalues use the touch panel's own range, which may differ from the screen resolution. - UI dump.
adb shell uiautomator dumpwrites 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 66Keycode 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_HOMEAdd --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:
| Code | Name | What it does |
|---|---|---|
| 3 | HOME | Go to the home screen |
| 4 | BACK | Back |
| 187 | APP_SWITCH | Recent apps |
| 82 | MENU | Legacy menu key; wakes some lock screens |
| 26 | POWER | Toggle the screen; long press for the power menu |
| 223 | SLEEP | Turn the screen off |
| 224 | WAKEUP | Turn the screen on |
| 24 / 25 | VOLUME_UP / VOLUME_DOWN | Volume |
| 164 | VOLUME_MUTE | Mute |
| 85 | MEDIA_PLAY_PAUSE | Play or pause media |
| 66 | ENTER | Submit or new line |
| 67 | DEL | Backspace |
| 61 | TAB | Move to the next field |
| 111 | ESCAPE | Close dialogs on some apps |
| 277 / 278 / 279 | CUT / COPY / PASTE | Clipboard actions in the focused field |
| 19 to 22 | DPAD_UP/DOWN/LEFT/RIGHT | Navigate focus, useful on TV and for accessibility checks |
Related commands for scripted testing
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 200With a PIN, follow up with input text 1234 and input keyevent 66. A dedicated test device without a lock is simpler and safer.
Open deep links, apps and the notification shade
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 collapseam 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 resetRemember 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
doneUse 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:
inputcommands 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 checkwm sizefirst.
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:
| Command | ADBKit equivalent |
|---|---|
input tap x y | Click on the mirrored screen |
input swipe | Click and drag on the screen |
input keyevent 4 / 3 / 187 | Back, Home and App Switcher buttons |
input keyevent 24 / 25 | Volume up and down buttons |
wm size for a different orientation | Rotation button |
- Open ADBKit, connect the phone over USB and click Connect device, then tap Allow on the phone.
- Start the live screen view; pick 720p in the stream quality setting if the connection is slow.
- 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.
- For
input text,am start,wm sizeor anything not on the toolbar, open the Shell drawer and type the command without theadb shellprefix.
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.