Ready-to-use Code ExampleRegionAssetColorSnap

Click Color in Region

Searches for a specific color within a defined area and taps the location if found. Asset.color() defines the target color, and mScore (0-1) sets the similarity threshold. The color is given in HEX format.

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 a color inside a region
-- targetColor: HEX color; score: similarity threshold from 0 to 1

local targetColor = "#FF4444"
local score = 0.85
local x, y, w, h = 100, 300, 900, 600

Snap.screenRefresh()
local region = Region(x, y, w, h)
local match = region:find(Asset.color(targetColor):mScore(score))

if match then
  toast("Color found at " .. match:getX() .. ", " .. match:getY())
  click(match)
  wait(300)
else
  toast("Color 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.