ADB
Android
Shell Commands
Input Events
Mobile Development

ADB Shell Input Events

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

adb shell input lets you simulate taps, swipes, key presses, and text entry on an Android device from the command line. It is a practical tool for quick automation, debugging, kiosk setups, and reproducing UI flows without touching the screen manually.

The Most Common Commands

The input tool covers a few high-value event types directly.

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

The last example sends keycode 66, which is the Enter key.

Entering Text

You can also type text into the currently focused field.

bash
adb shell input text hello

Spaces are awkward because the shell and input tool both interpret them. A common trick is to use %s for a space.

bash
adb shell input text hello%sworld

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

Useful Key Events

Some key events are especially common in Android testing.

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 are handy when you need to automate navigation without a full UI testing framework.

Long Press and Drag

A long press can be approximated with a swipe whose start and end coordinates are the same but with a duration.

bash
adb shell input swipe 500 1200 500 1200 1000

That presses at one location for roughly one second.

You can also use duration for controlled drags:

bash
adb shell input swipe 200 1400 800 400 600

This is often enough for simple gesture automation.

Finding Coordinates

The weak point of raw input commands is that they need screen coordinates. A quick way to discover them is to enable Pointer Location in Android developer options or inspect the device resolution.

bash
adb shell wm size

Knowing the device dimensions helps you choose stable tap and swipe positions.

Combining Input Commands

Simple automation often means chaining a few input commands together.

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 demo%40example.com
5adb shell input keyevent 66

This is not a replacement for a full testing framework, but it is fast and effective for repeatable setup steps.

When input Is Not Enough

adb shell input works best for straightforward interactions. It becomes fragile when:

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

For those cases, higher-level tools such as UI Automator, Espresso, or Appium are usually better.

A Practical Debugging Use Case

Suppose a bug only appears after a specific navigation path. Raw ADB input commands can reproduce that path quickly in a shell script or terminal history, which makes manual debugging much easier than tapping through the same screens repeatedly.

That is one reason these commands stay useful even in teams that already use larger automation frameworks.

Common Pitfalls

The biggest pitfall is relying on hard-coded coordinates across devices with different screen sizes or densities. A tap that works on one phone may miss entirely on another.

Another issue is sending text before the target field has focus. adb shell input text writes to the active input target, not to a specific view by identifier.

Developers also expect perfect behavior for complex text, symbols, or international input. The input text command is convenient, but it is not a full keyboard emulator.

Finally, remember that command timing matters. If the UI has not finished transitioning, the next input event can hit the wrong screen.

Summary

  • Use adb shell input to simulate taps, swipes, text entry, and key events.
  • 'tap, swipe, text, and keyevent are the core commands to know.'
  • Use %s for spaces when sending text.
  • Raw coordinates are fast for debugging but fragile across device layouts.
  • For stable UI automation, move to a higher-level Android testing tool when needed.

Course illustration
Course illustration

All Rights Reserved.