How to use the command "input" (with examples)

How to use the command "input" (with examples)

The “input” command is used to send event codes or touchscreen gestures to an Android device. It can only be used through the “adb shell” command and provides a way to interact with the device programmatically. This command is particularly useful for automating actions or simulating user input on an Android device.

Use case 1: Send an event code for a single character to an Android device

Code:

input keyevent event_code

Motivation:

This use case is helpful when you want to simulate key presses on an Android device. By sending an event code for a specific character, you can type text or trigger actions that require a key press.

Explanation:

  • “input” is the command used to interact with the Android device.
  • “keyevent” is the subcommand used to specify that we are sending an event code.
  • “event_code” is the code representing the desired key press. The codes can be found in the Android KeyEvent Constants documentation.

Example output:

Sending the event code for the letter “a”:

$ input keyevent 29

Use case 2: Send a text to an Android device

Code:

input text "text"

Motivation:

This use case allows you to send text to an Android device, simulating a user typing. It can be particularly useful for automation purposes or when you need to input a large amount of text.

Explanation:

  • “input” is the command used to interact with the Android device.
  • “text” is the subcommand used to specify that we are sending text.
  • “text” is the actual text that will be sent to the Android device. Surrounding the text in quotes is necessary to send spaces or special characters.

Example output:

Sending the text “Hello, World!”:

$ input text "Hello, World!"

Use case 3: Send a single tap to an Android device

Code:

input tap x_position y_position

Motivation:

This use case is useful when you want to simulate a user tapping on the screen of an Android device. It allows you to trigger actions that require touch input, such as clicking on buttons or selecting items.

Explanation:

  • “input” is the command used to interact with the Android device.
  • “tap” is the subcommand used to specify that we are sending a tap gesture.
  • “x_position” and “y_position” are the coordinates of the screen where the tap will be performed. The origin (0, 0) is the top-left corner of the screen.

Example output:

Sending a tap gesture at position (200, 300):

$ input tap 200 300

Use case 4: Send a swipe gesture to an Android device

Code:

input swipe x_start y_start x_end y_end duration_in_ms

Motivation:

This use case allows you to simulate a swipe gesture on the screen of an Android device. It is helpful when you want to perform actions that require swiping, such as scrolling or navigating through a list.

Explanation:

  • “input” is the command used to interact with the Android device.
  • “swipe” is the subcommand used to specify that we are sending a swipe gesture.
  • “x_start” and “y_start” are the coordinates where the swipe will begin.
  • “x_end” and “y_end” are the coordinates where the swipe will end.
  • “duration_in_ms” is the duration of the swipe gesture in milliseconds.

Example output:

Sending a swipe gesture from (100, 200) to (500, 200) with a duration of 1000 milliseconds:

$ input swipe 100 200 500 200 1000

Use case 5: Send a long press to an Android device using a swipe gesture

Code:

input swipe x_position y_position x_position y_position duration_in_ms

Motivation:

This use case allows you to simulate a long press on the screen of an Android device. By combining a swipe gesture with the same start and end position, you can trigger the long press action, which is commonly used for context menus or selecting items.

Explanation:

  • “input” is the command used to interact with the Android device.
  • “swipe” is the subcommand used to specify that we are sending a swipe gesture.
  • “x_position” and “y_position” are the coordinates where the swipe will begin and end, which are the same in this case.
  • “duration_in_ms” is the duration of the swipe gesture in milliseconds.

Example output:

Sending a long press gesture at position (300, 400) with a duration of 2000 milliseconds:

$ input swipe 300 400 300 400 2000

Conclusion:

The “input” command in Android provides a way to send event codes or touchscreen gestures to an Android device. By utilizing this command with different arguments, you can simulate user input, automate actions, or interact programmatically with the device. These examples demonstrate the versatility of the “input” command and how it can be used in various scenarios.

Related Posts

How to use the command smbget (with examples)

How to use the command smbget (with examples)

Smbget is a utility that allows users to download files from SMB (Server Message Block) servers, similar to the wget command for HTTP/HTTPS downloads.

Read More
Managing Databases in DigitalOcean using `doctl databases db` (with examples)

Managing Databases in DigitalOcean using `doctl databases db` (with examples)

DigitalOcean provides a command-line tool called doctl that allows users to interact with their resources in a programmatic way.

Read More
Exploring .NET Assemblies with Monop (with examples)

Exploring .NET Assemblies with Monop (with examples)

Introduction Monop is a command-line tool that allows developers to find and display signatures of types and methods within .

Read More