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.
-- Screen color check
-- checkX, checkY: the pixel; targetColor: HEX; tolerance: deltaE threshold
local checkX, checkY = 540, 960
local targetColor = "#22BB57"
local tolerance = 20
Snap.screenRefresh()
-- Read the pixel color
local pixelColor = Color.pixel(checkX, checkY)
if not pixelColor then
toast("Could not read the pixel")
return
end
toast("Pixel color: " .. Color.valueString(pixelColor))
-- Compare with the target color
if Color.isSimilar(pixelColor, targetColor, tolerance) then
toast("Color matches: the button is active")
click(Point(checkX, checkY))
else
toast("Color differs: the button is inactive")
end
-- Read the RGB channels
local r = Color.red(pixelColor)
local g = Color.green(pixelColor)
local b = Color.blue(pixelColor)
toast("RGB: " .. r .. ", " .. g .. ", " .. b)