ADB
Android
Shell Commands
Input Events
Mobile Development

adb shell input: tap, swipe, keyevent and text commands

Codemia Knowledge Hub ·

adb shell input simulates taps, swipes, key presses and text entry on an Android device from the command line. It is handy for quick automation, debugging, kiosk setups and reproducing UI flows without touching the screen.

Tap, swipe and keyevent

Simulate a tap:

bash
adb shell input tap 500 1200

Simulate a swipe:

bash
adb shell input swipe 300 1200 900 1200

Simulate a key press:

bash
adb shell input keyevent 66

Keycode 66 is the Enter key.

Typing text with input text

input text types into the currently focused field.

bash
adb shell input text hello

Spaces are awkward because both the shell and the input tool interpret them. Use %s for a space:

bash
adb shell input text hello%sworld

This works for quick test data entry, though complex Unicode and punctuation can still be finicky.

Common keyevent codes (Home, Back, Menu, Enter)

bash
1adb shell input keyevent 3   # Home
2adb shell input keyevent 4   # Back
3adb shell input keyevent 26  # Power
4adb shell input keyevent 82  # Menu
5adb shell input keyevent 66  # Enter

These let you automate navigation without a full UI testing framework.

Long press and drag with a swipe duration

A long press is a swipe that starts and ends at the same point, with a duration in milliseconds:

bash
adb shell input swipe 500 1200 500 1200 1000

That holds one spot for roughly one second. The same duration argument gives you controlled drags:

bash
adb shell input swipe 200 1400 800 400 600

Finding coordinates

Raw input commands need screen coordinates. Enable Pointer Location in Android developer options, or check the device resolution:

bash
adb shell wm size

Knowing the dimensions helps you pick stable tap and swipe positions.

Chaining commands into a script

bash
1adb shell input keyevent 3
2adb shell input swipe 500 1800 500 500 300
3adb shell input tap 300 700
4adb shell input text [email protected]
5adb shell input keyevent 66

This is no replacement for a testing framework, but it is fast for repeatable setup steps. It is also useful when a bug only appears after a specific navigation path: a short shell script reproduces the path far faster than tapping through the same screens by hand, which is why these commands stay useful even in teams with larger automation frameworks.

Where raw input breaks down

adb shell input gets fragile when:

  • the UI layout changes often
  • animations affect timing
  • elements move across devices and screen sizes
  • accessibility text or the view hierarchy matters more than raw coordinates

For those cases, UI Automator, Espresso or Appium are usually better.

Specific problems to watch for:

  • Hard-coded coordinates. A tap that works on one phone can miss entirely on a device with a different screen size or density.
  • Unfocused fields. input text writes to the active input target, not to a view by identifier, so the field must have focus first.
  • Complex text. input text is convenient, but it is not a full keyboard emulator for symbols or international input.
  • Timing. If the UI has not finished transitioning, the next event can land on the wrong screen.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms