Screen Class
The Screen object handles scaling, low-level screen inspection, and full-screen image detection.
Screen.getWidth()
Current target screen width, in pixels.
let result = Screen.getWidth();
console.log(result); // 1080Screen.getHeight()
Current target screen height, in pixels.
let result = Screen.getHeight();
console.log(result); // 1920Screen.getWidthDp()
The same screen in dp (pixels / density). Overlay widget sizes are dp, so this is the pair to size a HUD against. 0 when the screen cannot be read.
let result = Screen.getWidthDp();
console.log(result);Screen.getHeightDp()
The same screen in dp (pixels / density). Overlay widget sizes are dp, so this is the pair to size a HUD against. 0 when the screen cannot be read.
let result = Screen.getHeightDp();
console.log(result);Screen.getSourceWidth()
Original width used when the macro was created.
let result = Screen.getSourceWidth();
console.log(result); // 1080Screen.getSourceHeight()
Original height used when the macro was created.
let result = Screen.getSourceHeight();
console.log(result); // 1920Screen.scaleX(x)
Scale one X coordinate from source to current screen.
let result = Screen.scaleX(500);
console.log(result);Screen.scaleY(y)
Scale one Y coordinate from source to current screen.
let result = Screen.scaleY(1200);
console.log(result);Screen.scalePoint(x, y)
Return a scaled Point object (source → current screen).
let result = Screen.scalePoint(540, 960);
console.log(result); // (x, y)Screen.scale(x, y)
Return a scaled Point object (source → current screen).
let result = Screen.scale(500, 1200);
console.log(result);Screen.scaleRect(x, y, w, h)
Return a scaled Region object (source → current screen).
let result = Screen.scaleRect(120, 200, 360, 180);
console.log(result); // (x, y, w, h)Screen.getScaleFactor()
Get the active resolution scale factor.
let result = Screen.getScaleFactor();
console.log(result);Screen.isScaling()
Check whether the screen is currently scaled from source dimensions.
let result = Screen.isScaling();
console.log(result);Screen.getPixelColor(x, y)
Return a Color object for one pixel.
let result = Screen.getPixelColor(500, 1200);
console.log(result); // #FFCC00Screen.getPixel(x, y)
Return a Color object for one pixel.
let result = Screen.getPixel(500, 1200);
console.log(result); // #FFCC00Screen.getPixels(points)
Colors for many points, all read off one screenshot. Takes an array of Points or [x, y] pairs and returns Colors in the same order. Much faster than calling getPixelColor per point, which takes a screenshot each time.
let points = [new Point(500, 1200), new Point(520, 1200)];
let colors = Screen.getPixels(points); // one screenshot for the whole list
console.log(colors[0]); // #FFCC00Screen.getPixelColors(points)
Colors for many points, all read off one screenshot. Takes an array of Points or [x, y] pairs and returns Colors in the same order. Much faster than calling getPixelColor per point, which takes a screenshot each time.
let colors = Screen.getPixelColors([[500, 1200], [520, 1200]]);
console.log(colors[0]); // #FFCC00Screen.getPixelValues(points)
The same batched read, returning raw ARGB integers instead of Color objects. The fast path for a motion scan.
let points = [new Point(500, 1200), new Point(520, 1200)];
let before = Screen.getPixelValues(points);
wait(200);
let after = Screen.getPixelValues(points);
for (let i = 0; i < points.length; i++) {
if (after[i] !== before[i]) console.log(points[i] + " changed");
}Screen.findPixels(color, options?)
Return matching points for a color.
let result = Screen.findPixels(Color.fromHex('#00FF88'), { minScore: 0.95 });
console.log(result); // [(x, y), ...]findColors(...)
Return matching points for a color.
let result = findColors('demo');
console.log(result);Screen.find(template, options?)
Find one image/color match. template can be a string or an array of strings to search multiple images simultaneously.
let result = Screen.find('reward', 'demo');
console.log(result);Screen.intercept(template, options?)
Predictive interception across the whole screen (see Region.intercept).
let result = Screen.intercept('reward', 'demo');
console.log(result);Screen.follow(template, options?)
Hold-and-follow across the whole screen (see Region.follow).
let result = Screen.follow('reward', 'demo');
console.log(result);Screen.findAll(template, options?)
Find all matches on the entire screen.
let result = Screen.findAll('reward', 'demo');
console.log(result);Screen.waitFor(template, options?)
Wait for an image to appear on the entire screen.
Screen.waitFor('reward', 'demo');Screen.exists(template, options?)
Check if an image exists on the entire screen (returns boolean).
let result = Screen.exists('reward', 'demo');
console.log(result);Screen.findText(text, options?)
Find specific text on the entire screen.
let result = Screen.findText('Daily Reward Ready', 'demo');
console.log(result);Screen.waitForText(text, options?)
Wait for text to appear on the entire screen (default 5000ms timeout).
Screen.waitForText('Daily Reward Ready', 'demo');Screen.waitUntilTextGone(text, options?)
Wait until text disappears from the entire screen.
Screen.waitUntilTextGone('Daily Reward Ready', 'demo');Screen.readText(options?)
Read all OCR text on the entire screen.
let result = Screen.readText('demo');
console.log(result);Screen.clickText(text, options?)
Find and click text on the entire screen.
Screen.clickText('Daily Reward Ready', 'demo');Screen.capture(region?)
Capture a screenshot, optionally limited to a region.
let capture = Screen.capture(new Region(0, 0, Screen.getWidth(), Screen.getHeight()));
console.log(capture); // "/data/user/0/net.macroforge.app/cache/screenshot_123456789.png"Screen.getCenterPoint()
Get the center point of the current screen.
let result = Screen.getCenterPoint();
console.log(result);