This module provides device text control functions, including clipboard text retrieval and automated input capabilities on Android devices.
It allows developers to programmatically simulate text input, including support for multi-field forms using simulated tab and enter keys.
Key Features:
- Clipboard Access: Get the current content of the device's clipboard.
- Text Input: Simulate input into the currently focused or specified screen coordinates.
- Form Input Support: Use
\t(tab) and\n(enter) to fill multiple fields, ideal for login or registration forms.
Typical Usage:
- Fill input boxes in apps using
inputText(x, y, content)orinputText(content)if already focused. - Simulate structured form filling with
inputForm("user\tphone\tpassword\t"). - Read and utilize clipboard data using
getClipboardText().
All methods are automatically attached to the Device.prototype via internal utilities,
making them available on any device instance returned by Device.getMain().
Functions
(inner) getClipboardText() → {string|null}
Get the text content in the device clipboard.
Example
// Example: Retrieve the clipboard text from the main device
var { Device } = require("sigma/device");
var sigmaDevice = Device.getMain();
if (sigmaDevice != null) {
var tests = require("sigma/tests")
var ret = sigmaDevice.getClipboardText();
if (ret != null) {
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");
}
//If it executes successfully, it will return:
Congratulations, this API executes successfully.
Return value: my clipboard
Returns:
| string | null |
The clipboard text if available, or |
| string | content |
Enter the character content (Chinese, English, numbers, etc.). |
Returns:
| number |
|
| number | x |
<optional> |
(Optional) The x-coordinate where the device should tap before inputting text. |
| number | y |
<optional> |
(Optional) The y-coordinate where the device should tap before inputting text. |
| string | content |
The text to input. enter the character content (Chinese, English, numbers, etc.). |
Returns:
| number |
Returns 0 if successful, non-zero if it fails, and gets the error message via the lastError() function when it fails. |