Region

A rectangular screen area for finding images or colors, capturing an image, or drawing an outline. Coordinates use pixels on the current horizontal/vertical axes; after scaling and offsets, only the part inside the screen is used. Read its dimensions with x, y, width, height = region.

Syntax

Region(x, y, width, height, /, scale="fixed", anchor="none", scale_param=ScaleParam())

Constructor parameters

NameDescription
xNumber
Top-left X coordinate
Required · Positional only
No default
yNumber
Top-left Y coordinate
Required · Positional only
No default
widthNumber
Region width
Required · Positional only
No default
heightNumber
Region height
Required · Positional only
No default
scaleString
How coordinates adapt between full screens: fixed keeps pixels; auto scales X by width and Y by height; width or height scales both axes by that dimension. Uses the macro's source screen size, without rotating axes or using app window size.
Optional · Positional or named
Default: fixed
anchorString
Reference position for adapting coordinates: none (top-left), center, top, bottom, left, right, top_left, top_right, bottom_left, bottom_right. auto chooses the nearest edge or center.
Optional · Positional or named
Default: none
scale_paramScaleParam
**Applies to templates**. Template matching scale parameters.
Optional · Positional or named
Default: ScaleParam()

Returns

Example

region = Region(100, 200, 300, 400)
hit = region.find("img", 3000, threshold=0.8, rate=3.0)

Fields

NameDescription
xNumber
Top-left horizontal coordinate.
yNumber
Top-left vertical coordinate.
widthNumber
Region width in pixels.
heightNumber
Region height in pixels.
scaleString
How coordinates adapt between full screens: fixed keeps pixels; auto scales X by width and Y by height; width or height scales both axes by that dimension. Uses the macro's source screen size, without rotating axes or using app window size.
Default: fixed
anchorString
Reference position for adapting coordinates: none (top-left), center, top, bottom, left, right, top_left, top_right, bottom_left, bottom_right. auto chooses the nearest edge or center.
Default: none
scale_paramScaleParam
**Applies to templates**. Template matching scale parameters used by find/wait methods on this region.
Default: ScaleParam()
middle_pointPoint
Center point of this region.
Field example
search_area = Region(120, 240, 360, 420)
left = search_area.x
top = search_area.y
w = search_area.width
h = search_area.height
scale = search_area.scale
anchor = search_area.anchor
search_area.x = 300
search_area.scale_param = ScaleParam(auto_scale=True, template_scale="LONG_EDGE")
center = search_area.middle_point

# Unpack Region into x, y, width, height
x, y, width, height = search_area
Constructor example
search_region = Region(120, 240, 360, 420)
fixed_center = Region(120, 240, 360, 420, "fixed", "center")
left_lane = Region(120, 240, 360, 420, scale="width", anchor="left", scale_param=ScaleParam(auto_scale=True, template_scale="LONG_EDGE"))

Methods

25 methods

Region.highlighted

Return the screen areas currently outlined by scripts, including square outlines created by Point.highlight().

Syntax

Region.highlighted()

Returns

list[Region] — list of active highlighted regions.

Example

active_regions = Region.highlighted()
for area in active_regions:
    area.highlight("yellow", auto_hide_ms=500)

Region.full_screen

Return the full current screen region.

Syntax

Region.full_screen()

Returns

Region — A Region covering the current screen from (0, 0).

Example

scan = Region.full_screen()
hit = scan.find("ok", 2000)

Region.highlight_off

Turn off all active region highlights.

Syntax

Region.highlight_off()

Returns

None — No value.

Example

scan = Region(120, 260, 280, 160)
scan.highlight("green")
wait(1000)
Region.highlight_off()

Region.macro_width

Return the screen width of the device that created this macro, adapted to current screen orientation, when available.

Syntax

Region.macro_width()

Returns

Number? — Macro source screen width, or None when unavailable.

Example

macro_w = Region.macro_width()

Region.macro_height

Return the screen height of the device that created this macro, adapted to current screen orientation, when available.

Syntax

Region.macro_height()

Returns

Number? — Macro source screen height, or None when unavailable.

Example

macro_h = Region.macro_height()

Region.find

Find one occurrence of the template in this region. Retry until found or timeout; timeout=0 scans once. Screen capture must be ready. ScreenCapture.cache_on() makes searches reuse one captured image until cache_off(); automatic reuse otherwise lasts up to 100 ms. Use auto_cache_off() for the newest available image, at the cost of more capture work.

Syntax

region.find(template, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateString | Template
Template name or relative folder path without image extension in the current macro, or a Template object. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

Match — A Match with found=True when found; otherwise found=False after the scan or timeout. Never None.

Example

region = Region(80, 220, 420, 520)
hit = region.find("ok", 4000, 0.8, 4.0)
MacroPanel.notify(str(hit))

Region.find_multi

Scan inside this region and return all matches for one template when at least one is found. If timeout is omitted, only one scan pass is performed.

Syntax

region.find_multi(template, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateString | Template
Template name or relative folder path without image extension in the current macro, or a Template object. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

MatchList — All matches for the template, or empty list on timeout.

Example

region = Region(80, 220, 420, 520)
matches = region.find_multi("enemy", 3000)
MacroPanel.notify(str(matches))

Region.find_any

Scan this region and return when any template in the list is found. If timeout is omitted, only one scan pass is performed.

Syntax

region.find_any(templates, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateslist[String | Template]
Template names/relative folder paths without image extensions, or Template objects. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

MatchList — One Match per input template, in input order, when any is found; some may have found=False. An empty MatchList if none is found before timeout.

Example

region = Region(80, 220, 420, 520)
matches = region.find_any(["enemy_a", "enemy_b"], 2500)
MacroPanel.notify(str(matches))

Region.find_all

Scan this region and return only when every template in the list is found. If timeout is omitted, only one scan pass is performed.

Syntax

region.find_all(templates, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateslist[String | Template]
Template names/relative folder paths without image extensions, or Template objects. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

MatchList — One successful Match per input template in input order, or an empty MatchList if a scan does not find them all before timeout.

Example

region = Region(80, 220, 420, 520)
matches = region.find_all(["hp", "mp"], 5000)
MacroPanel.notify(str(matches))

Region.find_color

Find one sampled pixel closest to the target color in this region. Each red, green and blue channel must differ by no more than tolerance; the smallest largest-channel difference wins. Retry until found or timeout; timeout=0 scans once. Requires ready screen capture.

Syntax

region.find_color(color, timeout=0, tolerance=0, rate=3, interval=10)

Parameters

NameDescription
colorColor | String | Number
Target color.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
toleranceNumber
Allowed per-channel RGB delta from 0 to 255.
Optional · Positional or named
Default: 0
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3
intervalNumber
Requested distance in pixels between tested positions; at least 1. Smaller values inspect more pixels and may take longer. The distance may increase automatically for large areas.
Optional · Positional or named
Default: 10

Returns

Match — A Match with at most one Point in point, or found=False and an empty point list if no sampled pixel matches or capture is unavailable.

Example

scan = Region(80, 220, 420, 520)
hit = scan.find_color("#FF4CAF50", tolerance=8, interval=4)
if hit.found:
    click(hit.point[0], random=0)

Region.find_any_color

Find any of the target colors in this region using the RGB tolerance rule of find_color. Return at most one best sampled point per found color, in input order. Retry until any color is found or timeout; timeout=0 scans once. Requires ready screen capture.

Syntax

region.find_any_color(colors, timeout=0, tolerance=0, rate=3, interval=10)

Parameters

NameDescription
colorslist[Color | String | Number] | tuple[Color | String | Number]
Target colors.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
toleranceNumber
Allowed per-channel RGB delta from 0 to 255.
Optional · Positional or named
Default: 0
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3
intervalNumber
Requested distance in pixels between tested positions; at least 1. Smaller values inspect more pixels and may take longer. The distance may increase automatically for large areas.
Optional · Positional or named
Default: 10

Returns

Match — A Match with one best Point per found color in point, in input order. found=False and an empty point list if none matches or capture is unavailable.

Example

colors = ["#FF0000", "#00FF00", "#0000FF"]
hit = Region.full_screen().find_any_color(colors, tolerance=6)
if hit.found:
    click(hit, random=0)

Region.find_multi_color

Find all sampled pixels matching one target color using the RGB tolerance rule of find_color. A list or tuple of colors raises an error. Retry until at least one point is found or timeout; timeout=0 scans once. Requires ready screen capture.

Syntax

region.find_multi_color(color, timeout=0, tolerance=0, rate=3, interval=10)

Parameters

NameDescription
colorColor | String | Number
Single target color.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
toleranceNumber
Allowed per-channel RGB delta from 0 to 255.
Optional · Positional or named
Default: 0
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3
intervalNumber
Requested distance in pixels between tested positions; at least 1. Smaller values inspect more pixels and may take longer. The distance may increase automatically for large areas.
Optional · Positional or named
Default: 10

Returns

Match — A Match with matching sampled Points in point, closest color first. found=False and an empty point list if none matches or capture is unavailable.

Example

hit = Region(80, 220, 420, 520).find_multi_color("red", tolerance=4, interval=3)
if hit.found:
    first = hit.point[0]
    hit.highlight(color="yellow", auto_hide_ms=800)

Region.wait

Wait until the template disappears from this region. If timeout is omitted, only one scan pass is performed.

Syntax

region.wait(template, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateString | Template
Template name or relative folder path without image extension in the current macro, or a Template object. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

Match — The latest Match: found=False means the image is absent; found=True means it was still present when waiting ended. Never None. Requires ready screen capture; unavailable capture can also report found=False.

Example

region = Region(0, 0, 1080, 2400)
result = region.wait("loading", 8000)
MacroPanel.notify(str(result))

Region.wait_any

Wait until any template in the list disappears from this region. If timeout is omitted, only one scan pass is performed.

Syntax

region.wait_any(templates, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateslist[String | Template]
Template names/relative folder paths without image extensions, or Template objects. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

MatchList — The latest Match for each input template, in input order, on disappearance or timeout. Check each found value; False means that image is absent. Requires ready screen capture; unavailable capture can also report found=False.

Example

watch = ["loading", "syncing"]
result = region.wait_any(watch, 10000)
MacroPanel.notify(str(result))

Region.wait_all

Wait until all templates in the list disappear from this region. If timeout is omitted, only one scan pass is performed.

Syntax

region.wait_all(templates, timeout=0, threshold=0.7, rate=3.0)

Parameters

NameDescription
templateslist[String | Template]
Template names/relative folder paths without image extensions, or Template objects. Unknown names raise an error.
Required · Positional or named
No default
timeoutNumber
Maximum wait in milliseconds. Omitted, zero or negative values scan once. A scan already running may finish after this time.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Requested scans per second while waiting, limited to 1-60. Actual speed depends on recognition time.
Optional · Positional or named
Default: 3.0

Returns

MatchList — The latest Match for each input template, in input order, on disappearance or timeout. All found values are False only when every image is absent. Requires ready screen capture; unavailable capture can also report found=False.

Example

watch = ["loading", "syncing"]
result = region.wait_all(watch, 10000)
MacroPanel.notify(str(result))

Region.capture

Capture this screen area as a Template. Requires an active screen capture session with user consent. Unavailable capture or a region entirely outside the screen raises an error.

Syntax

region.capture(name=None)

Parameters

NameDescription
nameString?
A name saves the image into the current macro immediately; None creates a temporary image. Saving a named image is not allowed in a protected macro.
Optional · Positional or named
Default: None

Returns

Template — A Template containing the captured image.

Example

sample = Region(120, 280, 220, 120).capture()
saved = sample.save_as("buttons/top/enemy_slot")

Region.left

Shrink this region toward the left side. The right edge moves left by the requested amount.

Syntax

region.left(value=0.5)

Parameters

NameDescription
valueNumber
Width to remove: 0-1 is a fraction of the current width; above 1 is pixels, capped at the full width. Negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A new region narrowed from the right edge.

Example

full = Region(100, 200, 1000, 500)
left_focus = full.left(0.4)
left_focus_px = full.left(400)

Region.right

Shrink this region toward the right side. The left edge moves right by the requested amount.

Syntax

region.right(value=0.5)

Parameters

NameDescription
valueNumber
Width to remove: 0-1 is a fraction of the current width; above 1 is pixels, capped at the full width. Negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A new region narrowed from the left edge.

Example

full = Region(100, 200, 1000, 500)
right_focus = full.right(0.3)
right_focus_px = full.right(240)

Region.top

Shrink this region toward the top side. The bottom edge moves upward by the requested amount.

Syntax

region.top(value=0.5)

Parameters

NameDescription
valueNumber
Height to remove: 0-1 is a fraction of the current height; above 1 is pixels, capped at the full height. Negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A new region narrowed from the bottom edge.

Example

full = Region(100, 200, 1000, 500)
top_focus = full.top(0.25)
top_focus_px = full.top(120)

Region.bottom

Shrink this region toward the bottom side. The top edge moves downward by the requested amount.

Syntax

region.bottom(value=0.5)

Parameters

NameDescription
valueNumber
Height to remove: 0-1 is a fraction of the current height; above 1 is pixels, capped at the full height. Negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A new region narrowed from the top edge.

Example

full = Region(100, 200, 1000, 500)
bottom_focus = full.bottom(0.25)
bottom_focus_px = full.bottom(120)

Region.horizontal

Shrink horizontally toward the center by moving both left and right edges inward.

Syntax

region.horizontal(value=0.5)

Parameters

NameDescription
valueNumber
Total width to remove, split equally between both sides: 0-1 is a fraction, above 1 is pixels. Capped at the full width; negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A centered region with reduced width.

Example

full = Region(100, 200, 1000, 500)
center_lane = full.horizontal(0.5)
center_lane_px = full.horizontal(300)

Region.vertical

Shrink vertically toward the center by moving both top and bottom edges inward.

Syntax

region.vertical(value=0.5)

Parameters

NameDescription
valueNumber
Total height to remove, split equally between both sides: 0-1 is a fraction, above 1 is pixels. Capped at the full height; negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A centered region with reduced height.

Example

full = Region(100, 200, 1000, 500)
center_band = full.vertical(0.5)
center_band_px = full.vertical(200)

Region.middle

Shrink both width and height toward the center.

Syntax

region.middle(value=0.5)

Parameters

NameDescription
valueNumber
Amount removed from each dimension: 0-1 is a fraction of that dimension; above 1 is pixels. Split equally between opposite edges, capped at each dimension. Negative values raise an error.
Optional · Positional or named
Default: 0.5

Returns

Region — A centered region reduced on both axes.

Example

full = Region(100, 200, 1000, 500)
focus = full.middle(0.4)
focus_px = full.middle(160)

Region.highlight

Draw a rectangular outline around this region. Calling again on the same Region replaces its outline. Returns before drawing finishes; only the latest update before the next screen refresh is shown.

Syntax

region.highlight(color="green", line_width=2, auto_hide_ms=0, movable=False)

Parameters

NameDescription
colorColor | String | Number
Highlight color.
Optional · Positional or named
Default: green
line_widthNumber
Outline thickness in dp; values below 1 become 1.
Optional · Positional or named
Default: 2
auto_hide_msNumber
Auto-hide after N milliseconds. 0 disables auto-hide.
Optional · Positional or named
Default: 0
movableBoolean
Allow dragging the highlighted region and write the moved coordinates back into this Region.
Optional · Positional or named
Default: False

Returns

Region — Returns the same region after drawing highlight.

Example

scan = Region(120, 260, 280, 160)
scan.highlight("#FF00BCD4", line_width=3, auto_hide_ms=1500, movable=True)

Region.highlight_off

Remove the outline created by this Region.

Syntax

region.highlight_off()

Returns

Region — Returns the same region after turning highlight off.

Example

scan = Region(120, 260, 280, 160)
scan.highlight("green")
wait(1000)
scan.highlight_off()