RootAutomator2
RootAutomator2
root_automator.RootAutomator2
Modern replacement for RootAutomator: same root / adb touch injection goals, multi-touch, and streaming gestures, with improved OEM compatibility.
Tips
Since Pro 9.3, RootAutomator2 is the recommended API surface.
Table of contents
Methods
- exit
- flush
- longPress
- press
- swipe
- tap
- touchDown (single)
- touchDown (multi)
- touchMove (single)
- touchMove (multi)
- touchUp (by id)
- touchUp (multi)
Methods
tap
▸ tap(x, y): Promise<void>
5 ms tap at (x, y).
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.tap(200, 200);
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
x | number | X in pixels. |
y | number | Y in pixels. |
Returns
Promise<void>
swipe
▸ swipe(x1, y1, x2, y2, duration): Promise<void>
Linear swipe from (x1, y1) to (x2, y2) over duration ms.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.swipe(1000, 50, 1000, 1000, 300);
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
x1 | number | Start X. |
y1 | number | Start Y. |
x2 | number | End X. |
y2 | number | End Y. |
duration | number | Duration in ms. |
Returns
Promise<void>
press
▸ press(x, y, duration): Promise<void>
Hold (x, y) for duration ms, then release.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.press(1000, 500, 2000);
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
x | number | X in pixels. |
y | number | Y in pixels. |
duration | number | Hold time (ms). |
Returns
Promise<void>
longPress
▸ longPress(x, y): Promise<void>
Long press using ViewConfiguration.getLongPressTimeout() + 100 ms.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.longPress(1000, 500);
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
x | number | X in pixels. |
y | number | Y in pixels. |
Returns
Promise<void>
touchDown (single)
▸ touchDown(x, y, id?): Promise<void>
ACTION_DOWN at (x, y) for id. If that finger was already down, the runtime emits a move instead.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.touchDown(100, 100);
await ra.exit();
}
main();Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | number | undefined | X in pixels. |
y | number | undefined | Y in pixels. |
id | number | 0 | Pointer slot. |
Returns
Promise<void>
touchDown (multi)
▸ touchDown(pointers): Promise<void>
Simultaneous down for multiple Pointer contacts, e.g. touchDown([{ x: 100, y: 100, id: 0 }, { x: 200, y: 200, id: 1 }]).
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.touchDown([
{ x: 100, y: 100, id: 0 },
{ x: 200, y: 200, id: 1 },
]);
await ra.touchUp();
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
pointers | Pointer[] | Contacts to down. |
Returns
Promise<void>
touchUp (by id)
▸ touchUp(id?): Promise<void>
Lift one finger. Omit id to release all active pointers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | number | undefined | Pointer slot, or all if omitted. |
Returns
Promise<void>
touchUp (multi)
▸ touchUp(pointers): Promise<void>
Lift several fingers in one frame. Coordinates are the final touch locations reported with the up.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.touchDown([
{ x: 100, y: 100, id: 0 },
{ x: 200, y: 200, id: 1 },
]);
await ra.touchUp([
{ x: 150, y: 150, id: 0 },
{ x: 250, y: 250, id: 1 },
]);
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
pointers | Pointer[] | Fingers to lift. |
Returns
Promise<void>
touchMove (single)
▸ touchMove(x, y, id?): void
Move pointer id to (x, y). If it was not down, a down is synthesized first.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.touchDown(100, 100);
ra.touchMove(200, 200);
ra.touchMove(300, 300);
await ra.touchUp();
await ra.flush();
await ra.exit();
}
main();Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x | number | undefined | X in pixels. |
y | number | undefined | Y in pixels. |
id | number | 0 | Pointer slot. |
Returns
void
touchMove (multi)
▸ touchMove(pointers): Promise<void>
Batch move, e.g. touchMove([{ x: 100, y: 100, id: 0 }, { x: 200, y: 200, id: 1 }]).
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.touchDown([
{ x: 100, y: 100, id: 0 },
{ x: 200, y: 200, id: 1 },
]);
await ra.touchMove([
{ x: 150, y: 150, id: 0 },
{ x: 250, y: 250, id: 1 },
]);
await ra.touchUp();
await ra.flush();
await ra.exit();
}
main();Parameters
| Name | Type | Description |
|---|---|---|
pointers | Pointer[] | Targets to move. |
Returns
Promise<void>
flush
▸ flush(): Promise<void>
Await completion of all queued injections—useful after a chain of touchDown / touchMove / touchUp.
Example
"nodejs";
const { createRootAutomator2 } = require("root_automator");
async function main() {
const ra = await createRootAutomator2({ root: true });
await ra.touchDown(100, 100);
ra.touchMove(200, 200);
ra.touchMove(300, 300);
await ra.touchUp();
await ra.flush();
console.log("gesture queue drained");
await ra.exit();
}
main();Returns
Promise<void>
exit
▸ exit(forced?): Promise<void>
Stop the injector.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
forced | boolean | false | true exits ASAP without waiting for pending ops; false drains the queue first. |
Returns
Promise<void>
