This module provides various input-related operations for simulating user actions on Android devices,
such as taps, swipes, scrolls, key presses, and directional movements. It enables automated UI interactions,
and supports both single and multi-device operations with absolute or relative coordinate systems.
All functions are dynamically attached to Device.prototype, allowing usage like device.click(...), device.scroll(...), etc.
Key Features
- Touch Events: Precise taps using
clickand randomized area taps usingclick2. - Scroll Simulation: Scroll in any direction with pixel or ratio-based coordinates.
- Key Event Sending: Simulate key codes for HOME, BACK, VOLUME, letters, numbers, etc.
- Directional Movement: Use
shiftormovefor predefined navigation gestures. - Multi-point Swipes: Create complex gestures with
swipe, supporting finger indexing and delay. - Multi-device Support: Execute operations simultaneously on multiple connected devices.
Supported Input Modes
- Absolute coordinates (e.g.,
device.click(100, 200)) - Relative coordinates (e.g.,
device.click(0.5, 0.5)for center tap) - Predefined constants (e.g.,
tcConst.KEY_HOME,tcConst.movement.shiftPageDown)
Example
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
// Tap center of the screen
sigmaDevice.click(0.5, 0.5);
// Scroll up 1000 pixels
sigmaDevice.scroll(500, 800, 0, -1000);
// Send HOME key
sigmaDevice.send(tcConst.KEY_HOME);
Functions
(inner) click(x, y, stateopt) → {number}
Send a click event to click on the specified coordinates (x, y).
Example
// Example 1: Click at absolute pixel coordinates (123, 254) with touch state
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
var ret = sigmaDevice.click(123, 254, tcConst.STATE_DOWN);
if (ret == 0) {
print("Congratulations, this API executes successfully.\nReturn value: " + ret);
} else {
print("Sorry! " + lastError() + "\nReturn value: " + ret);
}
} else {
print("Failed to get the master device object");
}
// Example 2: Click at a relative position (12.5% width, 52.58% height)
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
var ret = sigmaDevice.click(0.1250, 0.5258); // Relative click
if (ret == 0) {
print("Congratulations, this API executes successfully.\nReturn value: " + ret);
} else {
print("Sorry! " + lastError() + "\nReturn value: " + ret);
}
} else {
print("Failed to get the master device object");
}
// Operation Result (if successful):
// Congratulations, this API executes successfully.
// Return value: 0
Parameters:
| number | x |
x coordinate, (relative coordinate / absolute coordinate). |
|
| number | y |
y coordinate, (relative coordinate / absolute coordinate). |
|
| string | state |
<optional> |
(Optional) The touch event type constant:
|
Returns:
| number |
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| number | x |
x coordinate, (relative coordinate / absolute coordinate). |
|||||||
| number | y |
y coordinate, (relative coordinate / absolute coordinate). |
|||||||
| Object | offset |
<optional> |
Optional parameters, consists of the keywords "dx" and "dy"; Properties
|
Returns:
| number |
result - If successful, it returns 0; if failed, it returns non-zero. In this case, you can use the lastError() function to get the specific error information. |
| string | code |
Constant value, key code value. A predefined movement constant from
|
Returns:
| number |
If the execution is successful, it returns 0; if the execution fails, it returns null. You can get the error information through lastError(). |
| number | x |
<optional> |
The starting x-coordinate (in pixels or ratio). Optional if using default position. |
| number | y |
<optional> |
The starting y-coordinate (in pixels or ratio). Optional if using default position. |
| number | dx |
Specifies the distance to scroll left or right. It supports relative and absolute coordinates. |
|
| number | dy |
Specifies the distance to scroll up or down, support relative and absolute coordinates. |
Returns:
| number |
result - If the execution is successful, it returns 0; if the execution fails, it returns null. You can get the error information through lastError(). |
| string | code |
The key code to send. Use predefined constants like |
||
| string | state |
<optional> |
tcConst.STATE_PRESS | (Optional) The key event type:
|
Returns:
| number |
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| string | direct |
The constant value of the direction.
|
Returns:
| number |
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| any | args |
<repeatable> |
Mode 1: ([x1, y1], [x2, y2], speed) for simple swipe.
Mode 2: (coord) where coord is an array of points with optional delay values
For example: |
Returns:
| number |
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function. |
| Array.<number> | from |
Starting point of the swipe. Format: [x, y]. |
||
| Array.<number> | to |
Ending point of the swipe. Format: [x, y]. |
||
| number | speed |
<optional> |
4 | Optional swipe speed level from 0 (slowest) to 5 (fastest). |
Returns:
| number | null |
This function returns 0 on success or non-zero on failure. Specific error information can be obtained by the lastError() function. |