Ready-to-use Code ExampleColorSnap

Screen Color Check

Reads the pixel color at specific coordinates and compares it with a target color. Color.pixel() reads color from screen, Color.isSimilar() compares two colors with tolerance. Used for state detection and screen analysis.

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.

-- Ekran renk kontrolu / Screen color check
-- Parametreler: koordinat, hedef renk, tolerans

local kontX, kontY = 540, 960
local hedefRenk = "#22BB57"
local tolerans = 20

Snap.screenRefresh()

-- Pikseldeki rengi oku
local pikselRenk = Color.pixel(kontX, kontY)
toast("Piksel rengi: " .. Color.valueString(pikselRenk))

-- Hedef renkle karsilastir
local benzer = Color.isSimilar(pikselRenk, hedefRenk, tolerans)
if benzer then
  toast("Renk eslesti - buton aktif")
  click(kontX, kontY)
else
  toast("Renk eslesmiyor - buton pasif")
end

-- RGB degerlerini ayri ayri oku
local r = Color.red(pikselRenk)
local g = Color.green(pikselRenk)
local b = Color.blue(pikselRenk)
toast("RGB: " .. r .. ", " .. g .. ", " .. b)

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.