Ready-to-use Code ExampleRegionSnapOCR

Click Text in Region

Uses OCR (optical character recognition) to find text within a defined area and taps it. Region:clickText() combines search and tap in a single call and returns true when the tap was dispatched.

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 text inside a region

local label = "Start"
local x, y, w, h = 0, 800, 1080, 400

Snap.screenRefresh()
local region = Region(x, y, w, h)
local param = FindParam.timeout(3000)

local tapped = region:clickText(label, param)
if tapped then
  toast("'" .. label .. "' tapped")
  wait(300)
else
  toast("Text not found: " .. label)
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.
  • For OCR examples, keep the text area clean; busy backgrounds or very small text can weaken recognition.