Example Scripts
Common tasks in GScript, with every option shown.
1. Basic Click
Click a specific point on the screen. The options object lets you configure exactly how the tap behaves.
click(540, 960, { duration: 50, repeat: 1, waitBefore: 0, waitAfter: 0, radius: 0 });2. Basic Swipe
Swipe from one coordinate to another.
swipe(100, 800, 100, 400, { duration: 300, repeat: 1, waitBefore: 0, waitAfter: 0 });3. Swipe with Holds (Path Swipe)
If you need to press and hold before moving, or trace a specific shape, you can pass an array of points instead.
let path = [
{ x: 100, y: 800, hold: 500, move: 300 }, // Hold for 500ms, then move for 300ms
{ x: 100, y: 400, hold: 0, move: 200 }, // Don't hold, then move for 200ms
{ x: 500, y: 400, hold: 100, move: 0 } // Hold for 100ms at the end
];
swipe(path, { repeat: 1, waitBefore: 0, waitAfter: 150 });4. Image Detection & Relative Click
Find an image on the screen, and then click relative to its position.
let searchRegion = new Region(0, 0, 1080, 1920);
let match = searchRegion.find("reward_button", { timeout: 5000 });
if (match) {
// Click 50px to the right of the match
click(match.x + 50, match.y, { duration: 50, repeat: 1, waitBefore: 0, waitAfter: 0, radius: 5 });
toast("Clicked the reward.");
} else {
toast("Could not find the reward.");
}5. Text Detection (OCR)
Find specific text within a region and interact with it.
// new Region(x, y, w, h).findText(text, options)
// Options: mode ('exact' or 'fuzzy')
let region = new Region(730, 130, 260, 70);
let match = region.findText("Claim", { mode: "exact" });
if (match) {
match.click();
} else {
console.warn("Text not found.");
}6. Multi-Touch (Pinch to Zoom)
Simulate two fingers moving at the same time to zoom in or out. You can use the built-in global pinchIn and pinchOut functions:
// Pinch OUT (zoom out): fingers start close at center point and move apart
pinchOut(CenterPoint().x, CenterPoint().y, 300, 400);
// Pinch IN (zoom in): fingers start far apart and move towards the center
pinchIn(CenterPoint().x, CenterPoint().y, 300, 400);For custom multi-touch gestures, you can use multi.swipe which accepts an array of swipe paths:
multi.swipe([
// Finger 1 moves left
[{ x: 500, y: 500 }, { x: 200, y: 500 }],
// Finger 2 moves right
[{ x: 600, y: 500 }, { x: 900, y: 500 }]
], { duration: 400 });7. Conditional Auto-Clicker
Click randomly within a specific area until a "stop" image appears.
let stopRegion = new Region(0, 0, 1080, 1920);
while (!stopRegion.find("stop_button", { timeout: 0 })) {
// Tap near the center with a 50px random radius
click(540, 960, { radius: 50, waitAfter: 100 });
}
toast("Stop button found, resting.");8. Custom UI Overlay Tracker
Draw custom text or shapes directly on top of the screen to track what your macro is doing in real-time.
Ui.Overlay.setPanel('statusBg', 40, 40, 300, 80, Color.fromHex('#AA000000'));
Ui.Overlay.setText('statusText', 'Hunting for targets...', 60, 65, Color.green(), 24);
wait(3000);
Ui.Overlay.setText('statusText', 'Target Acquired.', 60, 65, Color.red(), 24);
wait(2000);
Ui.Overlay.clearAll();9. Find All (Multiple Images)
You can pass an array of image templates to findAll to search for multiple different images at the same time, and it will return all of them that it finds.
let searchRegion = new Region(0, 0, 1080, 1920);
// Search for coins, gems, and stars simultaneously
let matches = searchRegion.findAll(["coin", "gem", "star"], { timeout: 5000 });
for (let match of matches) {
match.click();
wait(150); // Small pause between clicks
}
toast("Collected " + matches.length + " items!");10. Motion Detection (Click Whatever Moves)
When anything that moves is the target, sample a grid of points and click the one that changed most. Screen.getPixelValues(points) reads the whole grid from one screenshot; Screen.getPixelColor(x, y) takes a new screenshot per call and would be far too slow here.
let region = new Region(100, 400, 880, 1200);
let step = 10; // grid spacing, smaller than the target
let minDiff = 0.1; // 0-1: how different a point must be to count as movement
let points = [];
for (let x = region.x + step; x < region.x + region.w - step; x += step) {
for (let y = region.y + step; y < region.y + region.h - step; y += step) {
points.push(new Point(x, y));
}
}
let baseline = Screen.getPixelValues(points);
for (let scan = 0; scan < 360; scan++) {
let now = Screen.getPixelValues(points);
let changed = 0, maxDiff = 0, target = -1;
for (let i = 0; i < points.length; i++) {
if (now[i] === baseline[i]) continue; // unchanged
changed++;
let diff = Color.compare(baseline[i], now[i]);
if (diff > maxDiff) { maxDiff = diff; target = i; }
}
if (changed > points.length * 0.1) {
// Most of the grid moved, so the whole view changed.
console.log("Scene changed, stopping.");
break;
} else if (target >= 0 && maxDiff > minDiff) {
click(points[target]);
wait(1000);
}
wait(500);
}The baseline is not refreshed, so a target that stays still keeps being detected. Use baseline = now; to react only to new changes. If you have an image of the moving target, region.intercept(template, options) is better: it tracks the target and predicts where it will be.