root_automator - Root Automator
The root_automator module simulates touch input using root or ADB permissions. It supports multi-touch and dynamic gestures.
Starting from Pro 9.3, createRootAutomator2 is recommended for better device compatibility.
Table of contents
Interfaces
Functions
Functions
createRootAutomator
createRootAutomator(options?: RootAutomatorOptions ): Promise<RootAutomator>
Create a new RootAutomator instance.
You can specify whether to use root/ADB, input device paths, etc. See RootAutomatorOptions. If neither root nor ADB is specified, defaults are taken from getDefaultShellOptions.
If inputDevice is not specified, it is auto-detected. If detection fails, an error is thrown. You can also run getevent -t and operate the screen to find the input event device path, e.g. /dev/input/event5.
Example
"nodejs";
const { createRootAutomator } = require("root_automator");
async function main() {
const ra = await createRootAutomator({ root: true });
await ra.tap(100, 100);
await ra.exit();
}
main();Parameters
options: Root automator options.
Returns
Return a Promise, and return the RootAutomator object when resolved.
createRootAutomator2
createRootAutomator2(options?: ShellOptions ): Promise<RootAutomator2>
Create a new RootAutomator2 instance. RootAutomator2 has better device compatibility than RootAutomator.
You can specify whether to use root/ADB, etc. See ShellOptions. If neither root nor ADB is specified, defaults are taken from getDefaultShellOptions.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
const { delay } = require("lang");
const { device } = require("device");
const { screenWidth, screenHeight } = device;
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.tap(200, 200);
await delay(1000);
await ra.press(screenWidth / 2, screenHeight / 2, 500);
await delay(1000);
await ra.swipe(500, 800, 500, 1000, 300);
await delay(1000);
let p0 = {
x: screenWidth / 6,
y: screenHeight / 6,
};
let p1 = {
x: screenWidth - p0.x,
y: screenHeight - p0.y,
};
ra.touchDown([
{ x: p0.x, y: p0.y, id: 0 },
{ x: p1.x, y: p1.y, id: 1 },
]);
const steps = 20;
const stepX = Math.round((p1.x - p0.x) / steps) / 2;
const stepY = Math.round((p1.y - p0.y) / steps) / 2;
for (let i = 0; i < steps; i++) {
ra.touchMove([
{ x: p0.x + stepX * i, y: p0.y + stepY * i, id: 0 },
{ x: p1.x - stepX * i, y: p1.y - stepY * i, id: 1 },
]);
}
await ra.touchUp();
await ra.flush();
await ra.exit();
}
main().catch(console.error);Parameters
options: Options for RootAutomator2 creation.
Returns
Return a promise that resolves to a RootAutomator2 instance.
