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:
Simulate a swipe:
Simulate a key press:
Keycode 66 is the Enter key.
Typing text with input text
input text types into the currently focused field.
Spaces are awkward because both the shell and the input tool interpret them. Use %s for a space:
This works for quick test data entry, though complex Unicode and punctuation can still be finicky.
Common keyevent codes (Home, Back, Menu, 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:
That holds one spot for roughly one second. The same duration argument gives you controlled drags:
Finding coordinates
Raw input commands need screen coordinates. Enable Pointer Location in Android developer options, or check the device resolution:
Knowing the dimensions helps you pick stable tap and swipe positions.
Chaining commands into a script
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 textwrites to the active input target, not to a view by identifier, so the field must have focus first. - Complex text.
input textis 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.
Related reading
- Add a border outside of a UIView instead of inside
- Add a UIView above all, even the navigation bar
- Add an element to an array in Swift
- Add bottom border line to UI TextField view in SwiftUI / Swift / Objective-C / Xamarin
- Add entry to iOS .plist file via Cordova config.xml
- Add floating point value to android resources/values
- Add padding on view programmatically
- Add placeholder text inside UITextView in Swift?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo 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 courseData 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.