Ready-to-use Code ExampleRegionAssetSnapFindParam

Click Image in Region

Searches for an image template within a defined screen region and taps it if found. Asset.image() creates the visual template, Region defines the search area. FindParam sets the match threshold (0-1) and the timeout (ms).

Completion, parameter hints and type checking. Installation instructions and downloads are hosted on GitHub.

Copyable Example Code

You can paste this into the code editor; still verify target image, region, color, text, and timing values in your own device flow.

-- Click an image inside a region
-- x, y, w, h: the search area; score: match threshold from 0 to 1; timeoutMs: how long to keep scanning

local x, y, w, h = 0, 400, 1080, 800
local score = 0.85
local timeoutMs = 5000

Snap.screenRefresh()
local region = Region(x, y, w, h)
local param = FindParam.timeout(timeoutMs):mScore(score)

local match = region:find(Asset.image("target_button"), param)
if match then
  toast("Found, tapping")
  click(match)
  wait(300)
else
  toast("Image not found")
end

Implementation and Adaptation Notes

  • Before running, replace sample values such as image names, text, colors, coordinates, and file paths with your own macro values.
  • For examples that use Region or coordinates, retest the target area on different resolutions and DPI values.
  • Tune mScore, timeout, and scan rate in a test macro first, then move the verified values into the production macro.
  • Avoid overly wide Region areas; a tighter area scans faster and reduces false matches.