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);
Methods
(static) 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:
| Name | Type | Attributes | Description |
|---|---|---|---|
x |
number | x coordinate, (relative coordinate / absolute coordinate). |
|
y |
number | y coordinate, (relative coordinate / absolute coordinate). |
|
state |
string |
<optional> |
(Optional) The touch event type constant:
|
Returns:
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function.
- Type
- number
(static) click2(x, y, offsetopt) → {number}
Click on the random coordinates in the specified area of the screen, that is, randomly click on a certain location within the specified area.
Example
// Randomly click on the specified area of the screen
// The offset range relative to the x coordinate is: 200 - 20/2 —— 200 + 20/2;
// The offset range relative to the y coordinate is: 200 - 10/2 —— 200 + 10/2;
// That is, the value range of the x coordinate is 195 —— 205, and the value range of the y coordinate is 195 —— 205
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
sigmaDevice.click2(200, 200, {dx: 20, dy: 10});
} else {
print("Failed to get the master device object");
}
Parameters:
| Name | Type | Attributes | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
x |
number | x coordinate, (relative coordinate / absolute coordinate). |
||||||||||
y |
number | y coordinate, (relative coordinate / absolute coordinate). |
||||||||||
offset |
Object |
<optional> |
Optional parameters, consists of the keywords "dx" and "dy"; Properties
|
Returns:
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.
- Type
- number
(static) move(code) → {number}
Move the page based on system setting swipe/scroll.
Example
// Example 1: Move the device screen up by one full page
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.move(tcConst.movement.pageUp);
if (ret == 0) print("Succeed to move");
// Example 2: Move the screen down slightly
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.move(tcConst.movement.down);
// Example 3: Multiple devices move down by one full page simultaneously
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevices = Device.searchObject(sigmaConst.DevAll);
var ret = sigmaDevices.move(tcConst.movement.pageDown);
// Operation Result:
If successful:
Move successfully
Parameters:
| Name | Type | Description |
|---|---|---|
code |
string | Constant value, key code value. A predefined movement constant from
|
Returns:
If the execution is successful, it returns 0; if the execution fails, it returns null. You can get the error information through lastError().
- Type
- number
(static) scroll(xopt, yopt, dx, dy) → {number}
Scrolls the specified range from the specified scroll area position in the specified direction. Supports scrolling up one or more pages, scrolling down one or more pages, scrolling left one or more pages or scrolling right one or more pages, and supporting multiple devices to scroll simultaneously.
Simulates a scroll (swipe) gesture on the screen from a given coordinate by a specified offset.
Supports both absolute pixel coordinates and relative screen ratios, and can be used for single or multiple devices.
If x and y are omitted, the default scroll start point is used.
x and y are Optional, pointing to the area that the scrolling will take place, supporting absolute and relative coordinates. By default, By default, the mouse position is used. If the mouse position cannot be found, the screen center point is used (x = width / 2, y = height / 2). Different applications have different scroll areas, and there may be multiple scroll areas on the screen.
Example
// Example 1: Scroll up 1000 pixels from point (500, 700)
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.scroll(500, 700, 0, 1000);
if (ret == 0) print("Scroll successfully");
// Example 2: Scroll down 1000 pixels from point (500, 700)
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.scroll(500, 700, 0, -1000);
// Example 3: Scroll left 1000 pixels from point (500, 700) on multiple devices
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevices = Device.searchObject(sigmaConst.DevAll);
var ret = sigmaDevices.scroll(500, 700, -1000, 0);
// Example 4: Scroll right by 20% of the screen width from position (50%, 60%) on multiple devices
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevices = Device.searchObject(sigmaConst.DevAll);
var ret = sigmaDevices.scroll(0.5, 0.6, 0.2, 0);
// Example 5: Scroll right 1000 pixels from default starting point on multiple devices
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevices = Device.searchObject(sigmaConst.DevAll);
var ret = sigmaDevices.scroll(1000, 0); // x and y are omitted
// Operation Result:
// If successful, returns: Scroll successfully
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
x |
number |
<optional> |
The starting x-coordinate (in pixels or ratio). Optional if using default position. |
y |
number |
<optional> |
The starting y-coordinate (in pixels or ratio). Optional if using default position. |
dx |
number | Specifies the distance to scroll left or right. It supports relative and absolute coordinates. |
|
dy |
number | Specifies the distance to scroll up or down, support relative and absolute coordinates. |
Returns:
result - If the execution is successful, it returns 0; if the execution fails, it returns null. You can get the error information through lastError().
- Type
- number
(static) send(code, stateopt) → {number}
Send a key event, such as home, menu, back, etc., to realize the key press and bounce event, or directly send a click event (press + bounce) to complete the click action. Total Control supports Android KEYCODE on keyboards and mobile phones.
key code value:
- Device keys:
Back key: KEYCODE_BACK or tcConst.KEY_BACK;
Home key: KEYCODE_HOME or tcConst.KEY_HOME;
Power key: KEYCODE_POWER or tcConst.KEY_POWER;
Menu key: KEYCODE_MENU or tcConst.KEY_MENU;
Search key: KEYCODE_SEARCH or tcConst.KEY_SEARCH;
RecentApp key: KEYCODE_RECENTAPP or tcConst.KEY_RECENTAPP. - Keyboard keys:
1). Function keyboard area
F1-F12: The format is KEYCODE_x or tcConst.KEY_x, where x is A-Z, such as KEYCODE_F1 or tcConst.KEY_F1.
Esc key: KEYCODE_ESCAPE or tcConst.KEY_ESCAPE.
2). Main keyboard area
A-Z letters: The format is KEYCODE_x or tcConst.KEY_x, where x is A-Z, such as KEYCODE_A or tcConst.KEY_A.
0-9 numbers: The format is KEYCODE_x or tcConst.KEY_x, where x is 0-9, such as KEYCODE_0 or tcConst.KEY_0.
Tab key: KEYCODE_TAB or tcConst.KEY_TAB.
BackSpace key: KEYCODE_BACK_SPACE or tcConst.KEY_BACK_SPACE.
CapsLock key: KEYCODE_CAPS_LOCK or tcConst.KEY_CAPS_LOCK.
Enter key: KEYCODE_ENTER or tcConst.KEY_ENTER.
Space key: KEYCODE_SPACE or tcConst.KEY_SPACE.
'' key: KEYCODE_SLASH or tcConst.KEY_SLASH.
'/' key: KEYCODE_BACKSLASH or tcConst.KEY_BACKSLASH.
',' key: KEYCODE_COMMA or tcConst.KEY_COMMA.
'-' key: KEYCODE_MINUS or tcConst.KEY_MINUS.
'=' key: KEYCODE_EQUALS or tcConst.KEY_EQUALS.
''' (apostrophe) key: KEYCODE_APOSTROPHE or tcConst.KEY_APOSTROPHE.
';' key: KEYCODE_SEMICOLON or tcConst.KEY_SEMICOLON.
'.' key: KEYCODE_PERIOD or tcConst.KEY_PERIOD.
'`' (backtick) key: KEYCODE_GRAVE or tcConst.KEY_GRAVE.
'[' key: KEYCODE_LEFT_BRACKET or tcConst.KEY_LEFT_BRACKET.
']' key: KEYCODE_RIGHT_BRACKET or tcConst.KEY_RIGHT_BRACKET.
Left Alt modifier key: KEYCODE_ALT_LEFT or tcConst.KEY_ALT_LEFT.
Left Control modifier key: KEYCODE_CTRL_LEFT or tcConst.KEY_CTRL_LEFT.
Left Shift modifier key: KEYCODE_SHIFT_LEFT or tcConst.KEY_SHIFT_LEFT.
Left Win modifier key: KEYCODE_WIN_LEFT or tcConst.KEY_WIN_LEFT.
Right Win modifier key: KEYCODE_WIN_RIGHT or tcConst.KEY_WIN_RIGHT.
3). Edit control keyboard area
PageUp key: KEYCODE_PAGE_UP or tcConst.KEY_PAGE_UP or tcConst.KEY_PGUP.
PageDown key: KEYCODE_PAGE_DOWN or tcConst.KEY_PAGE_DOWN or tcConst.KEY_PGDN.
End key: KEYCODE_END or tcConst.KEY_END. Delete key: KEYCODE_DEL or tcConst.KEY_DEL.
Up key: KEYCODE_UP or tcConst.KEY_UP. Down key: KEYCODE_DOWN or tcConst.KEY_DOWN.
Left key: KEYCODE_LEFT or tcConst.KEY_LEFT.
Right key: KEYCODE_RIGHT or tcConst.KEY_RIGHT.
4). Numeric keypad area
0-9 numbers: the format is KEYCODE_NUMPAD_x or tcConst.KEY_NUMPAD_x, where x is 0-9, such as KEYCODE_NUMPAD_0 or tcConst.KEY_NUMPAD_0.
Numeric keypad '+' key: KEYCODE_NUMPAD_ADD or tcConst.KEY_NUMPAD_ADD.
Numeric keypad '-' key: KEYCODE_NUMPAD_SUBTRACT or tcConst.KEY_NUMPAD_SUBTRACT.
Numeric keypad '*' key: KEYCODE_NUMPAD_MULTIPLY or tcConst.KEY_NUMPAD_MULTIPLY.
Numeric keypad '/' key: KEYCODE_NUMPAD_DIVIDE or tcConst.KEY_NUMPAD_DIVIDE.
Enter key: KEYCODE_NUMPAD_ENTER or tcConst.KEY_NUMPAD_ENTER.
NumLock key: KEYCODE_NUM_LOCK or tcConst.KEY_NUM_LOCK.
5). Key combination, only for API prototype send (code)
tcConst.KEY_S_UP: Shift + ↑, the mobile screen page moves up a bit, "Shift + ↑" moves faster and larger than "↑".
tcConst.KEY_S_DOWN: Shift + ↓, the mobile screen page moves down a bit, "Shift + ↓" moves faster and larger than "↓".
tcConst.KEY_S_LEFT: Shift + ←, the mobile screen page moves a little to the left, "Shift + ←" moves faster and larger than "←".
tcConst.KEY_S_RIGHT: Shift + →, the screen page of the mobile phone moves a little to the right, "Shift + →" moves faster and larger than "→".
tcConst.KEY_S_PGUP: Shift + PgUp, mobile phone screen page moves up several screens, "Shift + PgUp" moves faster and larger than "pgUp".
tcConst.KEY_S_PGDN: Shift + PgDn, the mobile screen page moves down a few screens, "Shift + PgDn" moves faster and larger than "pgDn".
Example
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
// Send a HOME key press event
sigmaDevice.send(tcConst.KEY_HOME, tcConst.STATE_DOWN);
// Send a HOME key release event
sigmaDevice.send(tcConst.KEY_HOME, tcConst.STATE_UP);
// Send a HOME key full press (press & release)
sigmaDevice.send(tcConst.KEY_HOME, tcConst.STATE_PRESS);
// Equivalent to STATE_PRESS (default behavior if state is missing)
sigmaDevice.send(tcConst.KEY_HOME);
// Send POWER button press (hold down)
sigmaDevice.send(tcConst.KEY_POWER, tcConst.STATE_DOWN);
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
code |
string | The key code to send. Use predefined constants like |
||
state |
string |
<optional> |
tcConst.STATE_PRESS
|
(Optional) The key event type:
|
Returns:
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function.
- Type
- number
(static) shift(direct) → {number}
Operate the device, slide the operation screen.
Example
// Example: Simulate a "LEFT" directional key input
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
var ret = sigmaDevice.shift(tcConst.KEY_LEFT);
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:
| Name | Type | Description |
|---|---|---|
direct |
string | The constant value of the direction.
|
Returns:
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function.
- Type
- number
(static) swipe(…args) → {number}
Simulate user operation screens, touch events. Sliding events for single or multi-point operations can be implemented. A touch event that simulates a user's operation, enabling a single or multi-point sliding event. If the "coord" array consists of 2 points with no delay, you can use swape([x1, y1], [x2, y2], speed). Coordinate format: the first coordinate group in the array is the pressed coordinate; the last coordinate group in the array is the lifting coordinates; the middle array is the sliding coordinate
Supports:
- swipe(coord) - single or multiple sliding coordinates (single point or multiple points)
- swipe([x1, y1], [x2, y2], speed) - slide from the starting point to the end point, the default speed is 4
The coord object used in the script to store screen coordinates, whose member variables include:
- x: int, The x coordinate of the pixel in the screen.
- y: int, The y coordinate of the pixel in the screen.
Example
// Example 1: Single-point sliding (relative coordinates)
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe([[0, 0, 30], [0.1, 0.2, 100], [0.5, 0.8, 1]]);
if (ret == 0) print("Sliding operation succeeded");
// Example 2: Multi-point sliding (absolute coordinates)
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe([[124, 256, 255, 296, 30], [224, 296, 340, 432, 100], [324, 356, 435, 567, 1]]);
if (ret == 0) print("Sliding operation succeeded");
// Example 3: Two-point sliding with no delay
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe([0, 0], [500, 800], 2); // finger index 2
if (ret == 0) print("Sliding operation succeeded");
// Operation Result:
If it executes successfully, it will return:
Sliding operation succeeded
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<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:
result - This function returns 0 on success or -1 on failure. Specific error information can be obtained by the lastError() function.
- Type
- number
(static) swipe2(from, to, speedopt) → {number|null}
Simulates a smooth swipe gesture between two points with adjustable speed and coordinate type.
This function supports absolute and relative coordinates. If absolute coordinates are detected,
they are automatically converted to relative before performing the swipe.
Internally, the swipe path is built from high-granularity points based on the distance between two points,
and each step uses a predefined delay from the speed level.
Example
// Example 1: Absolute coordinates: swipe from (100, 200) to (500, 800) at speed 3
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe2([100, 200], [500, 800], 3);
if (ret == 0) print("Swipe success");
// Example 2: Relative coordinates: swipe from 20% width, 30% height to 60% width, 80% height
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe2([0.2, 0.3], [0.6, 0.8], 2);
// Example 3: Swipe with default speed (4)
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe2([0.1, 0.1], [0.9, 0.9]);
// Example 4: Error case: invalid speed
var { Device } = require('sigma/device');
var input = require("sigma/input");
var sigmaDevice = Device.getMain();
var ret = sigmaDevice.swipe2([100, 200], [500, 800], 10);
if (ret == null) print("Error: " + lastError());
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
from |
Array.<number> | Starting point of the swipe. Format: [x, y]. |
||
to |
Array.<number> | Ending point of the swipe. Format: [x, y]. |
||
speed |
number |
<optional> |
4
|
Optional swipe speed level from 0 (slowest) to 5 (fastest). |
Returns:
This function returns 0 on success or non-zero on failure. Specific error information can be obtained by the lastError() function.
- Type
- number | null