Skip to main content

Input API


Description

IDroidInputAPI Input

Gives you access to emulate actions on your device for interacting with the interface and app elements. You use this interface to perform swipes, taps, and enter text, as well as execute ADB Shell commands.


Methods

Swipe the screen from point to point

void Swipe(int x1, int y1, int x2, int y2) 

Parameters:

int x1, int y1 // Coordinates of the first point.
int x2, int y2 // Coordinates of the second point.

Overload:

int duration  // How long the swipe takes (speed).  

Example

//#1
var input = instance.DroidInstance.Input;

Point start = new Point() { X = 100, Y = 500 }; // Start point
Point end = new Point() { X = 200, Y = 200 }; // End point
input.Swipe(start.X, start.Y, end.X, end.Y); // Swipe by coordinates

//#2
var duration = 100;
input.Swipe(start.X, start.Y, end.X, end.Y, duration); // Swipe with custom speed

Curved swipe from point to point

void SwipeCurved(int x1, int y1, int x2, int y2, int duration) 

Parameters:

int x1, int y1 // Coordinates of the first point.
int x2, int y2 // Coordinates of the second point.
int duration // Swipe speed.

Example

var input = instance.DroidInstance.Input;

Point start = new Point() { X = 100, Y = 500 }; // Start point
Point end = new Point() { X = 200, Y = 200 }; // End point
var duration = 100; // Swipe speed
input.SwipeCurved(start.X, start.Y, end.X, end.Y, duration); // Curved swipe

Curved swipe with bend control

void SwipeCurved(int x1, int y1, int xPivot, int yPivot, int x2, int y2, int duration) 

Parameters:

int x1, int y1 // Coordinates of the first point.
int xPivot // X of the pivot point.
int yPivot // Y of the pivot point.
int x2, int y2 // Coordinates of the second point.
int duration // Swipe speed.

Example

var input = instance.DroidInstance.Input;

Point start = new Point() { X = 100, Y = 500 }; // Start point
Point end = new Point() { X = 200, Y = 200 }; // End point
var duration = 100; // Swipe speed
var xPivot = 200; // X of the bend
var yPivot = 700; // Y of the bend
input.SwipeCurved(start.X, start.Y, xPivot, yPivot, end.X, end.Y, duration); // Curved swipe with bend settings

Tap by coordinates

void Tap(int x, int y) 

Parameters:

int x // X coordinate.
int y // Y coordinate.

Overload:

int duration  // Duration of the tap.  

Example

var input = instance.DroidInstance.Input;

Point point = new Point() { X = 100, Y = 500 }; // The point
input.Tap(point.X, point.Y); // Tap by coordinates

var duration = 100; // Tap duration
input.Tap(point.X, point.Y, duration); // Long tap by coordinates

Tap by coordinates with extra options

void Touch(int xMin, int yMin, int xMax, int yMax, bool longPress, string clickDistributionType)

Parameters:

int xMin, int yMin // Lower point coordinates.
int xMax, int yMax // Upper point coordinates.
bool longPress // Use a long tap
string clickDistributionType // Click type: "Normal" or "Random".

Example

var input = instance.DroidInstance.Input;

Point start = new Point() { X = 100, Y = 500 }; // Start
Point end = new Point() { X = 200, Y = 200 }; // End

input.Touch(start.X, start.Y, end.X, end.Y, false, "Random"); // Tap with options

Long tap and swipe the screen

void LongTapAndSwipe(int x1, int y1, int x2, int y2)

Parameters:

int x1, int y1 // Coordinates of the first point.
int x2, int y2 // Coordinates of the second point.

Overload:

int duration  // How long the swipe takes (speed).  

Example

var input = instance.DroidInstance.Input;

Point start = new Point() { X = 100, Y = 500 }; // Start point
Point end = new Point() { X = 200, Y = 200 }; // End point

input.LongTapAndSwipe(start.X, start.Y, end.X, end.Y); // Long tap and swipe

var duration = 100; // Duration
input.LongTapAndSwipe(start.X, start.Y, end.X, end.Y, duration); // Long tap and swipe with swipe speed setting

Enter text into a field

void SendText(string text)

Parameters:

string text // Text to enter.

Overload:

int latency // Delay between characters.  

Example

var input = instance.DroidInstance.Input;

var text = "Hello world!";
input.SendText(text); // Enter text in a field

var latency = 100; // Typing speed
input.SendText(text, latency); // Enter text with typing speed specified

Enter special characters (via KeyCode)

void SendKeyCode(KeyCode keyCode)

Parameters:

KeyCode keyCode // Special character identifier.

Overload:

int keyCode // Numeric code for the special character.  

Example

var input = instance.DroidInstance.Input;

input.SendKeyCode(KeyCode.KEYCODE_HOME); // Send special character (by name)
input.SendKeyCode(3); // Send special character (by number)

Clear the text field

void ClearText()

Example

var input = instance.DroidInstance.Input;

input.ClearText(); // Clear element text

Execute an ADB Shell command

string Shell(string command)

Parameters:

string command // ADB command to run.

Overload:

int timeout // Command timeout.  
bool checkconnect // Whether to check device connection.

Example

var input = instance.DroidInstance.Input;

var adb = "dumpsys activity activities | grep ResumedActivity"; // Command to get the current activity
var activity = input.Shell(adb); // Get the current activity

var adb = "am start -n com.example.app/.MainActivity"; // Command to launch app with activity
input.Shell(adb, 1000); // Launch app and wait for execution

var adb = "reboot"; // Reboot command
input.Shell(adb, 1000, true); // Reboot with wait and connection check

Get text from Clipboard

string GetClipboard()

Example

var input = instance.DroidInstance.Input;

var text = input.GetClipboard(); // Get text from clipboard

Copy text to Clipboard

void SetClipboard(string text)

Parameters:

string text // Text to put in clipboard.

Example

var input = instance.DroidInstance.Input;

var text = "Hello world!";
input.SetClipboard(text); // Copy text to clipboard

Zoom in the screen

void ZoomIn()

Overload:

int centerX // X of the center.
int centerY // Y of the center.
double ratio // Zoom amount.

Example

var input = instance.DroidInstance.Input;

input.ZoomIn(); // Zoom in
input.ZoomIn(-1, -1, 1.0); // Zoom in with additional settings

Zoom out the screen

void ZoomOut()

Overload:

int centerX // X of the center.
int centerY // Y of the center.
double ratio // Zoom out amount.

Example

var input = instance.DroidInstance.Input;

input.ZoomOut(); // Zoom out
input.ZoomOut(-1, -1, 1.0); // Zoom out with additional settings

Simulate receiving an SMS on the device

void SendSmsMessage(string phone, string message)

Parameters:

string phone // Fake sender phone number.
string message // The SMS text to be received.

Example

var input = instance.DroidInstance.Input;

var phone = "+79998007060";
var message = "Hi!";
input.SendSmsMessage(phone, message); // Simulate incoming SMS

You can read about the difference between ways of sending keystrokes in detail in the ADB Shell Commands.