Region

A rectangular region on the screen, measured in pixels on the current screen axes. Scale/anchor control coordinate mapping across full-screen sizes without rotating through portrait coordinates or using the app viewport; runtime consumers clip the final region to the current screen after mapping and offsets. ScaleParam controls template matching inside this region. Region can be destructured as x, y, width, height.

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
**Applies to region coordinates**. Optional full-screen scale mode on the current X/Y axes. Values: "fixed", "auto", "width", "height".
Optional · Positional or named
Default: fixed
anchorString
**Applies to region coordinates**. Optional anchor mode. Values: none, center, top, bottom, left, right, top_left, top_right, bottom_left, bottom_right, auto.
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
**Applies to region coordinates**. Coordinate scale mode using full-screen dimensions on the current X/Y axes, without app viewport scaling or portrait rotation. Values: "fixed" keeps saved pixels unchanged; "auto" scales X by width and Y by height; "width" scales both axes by screen width; "height" scales both axes by screen height.
Default: fixed
anchorString
**Applies to region coordinates**. Coordinate anchor. Values: none, center, top, bottom, left, right, top_left, top_right, bottom_left, bottom_right, auto.
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

Get all regions currently highlighted by script instances.

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 — Screen-sized region from the runtime host.

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

Scan inside this region until one template match is found or timeout is reached. If timeout is omitted, only one scan pass is performed. Use ScreenCapture.cache_on() to check several images in one pinned frame, then cache_off() to unpin it. For rapid recognition with the freshest available frame, also use ScreenCapture.auto_cache_off(); automatic caching otherwise reuses frames for up to 100 ms. Disabling it increases capture work and does not guarantee faster execution.

Syntax

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

Parameters

NameDescription
templateString | Template
Template name, relative folder path, or a Template object in current macro.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
Optional · Positional or named
Default: 3.0

Returns

Match — First successful match, or found=false when timed out.

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, relative folder path, or a Template object in current macro.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
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 or Template objects.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
Optional · Positional or named
Default: 3.0

Returns

MatchList — Batch match results when any template is found, or empty list on 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 or Template objects.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
Optional · Positional or named
Default: 3.0

Returns

MatchList — Batch match results when all templates are found, or empty list on timeout.

Example

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

Region.find_color

Scan this region for one target color using the same raw-frame RGB tolerance rule as UI color recognition. The best point is selected by the smallest max RGB channel delta.

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 time in milliseconds. 0 performs one scan pass.
Optional · Positional or named
Default: 0
toleranceNumber
Allowed per-channel RGB delta from 0 to 255.
Optional · Positional or named
Default: 0
rateNumber
Scan attempts per second while waiting.
Optional · Positional or named
Default: 3
intervalNumber
Sampling step in pixels.
Optional · Positional or named
Default: 10

Returns

Match — Match with point as list[Point]; find_color returns at most one point.

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

Scan this region for multiple target colors. Each input color contributes at most one best point, ordered by the input color list.

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 time in milliseconds. 0 performs one scan pass.
Optional · Positional or named
Default: 0
toleranceNumber
Allowed per-channel RGB delta from 0 to 255.
Optional · Positional or named
Default: 0
rateNumber
Scan attempts per second while waiting.
Optional · Positional or named
Default: 3
intervalNumber
Sampling step in pixels.
Optional · Positional or named
Default: 10

Returns

Match — Match with point as list[Point]; one best point per found input color.

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

Scan this region for multiple sampled positions of one target color. Passing a list or tuple is rejected so this does not silently become multi-target color search.

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 time in milliseconds. 0 performs one scan pass.
Optional · Positional or named
Default: 0
toleranceNumber
Allowed per-channel RGB delta from 0 to 255.
Optional · Positional or named
Default: 0
rateNumber
Scan attempts per second while waiting.
Optional · Positional or named
Default: 3
intervalNumber
Sampling step in pixels.
Optional · Positional or named
Default: 10

Returns

Match — Match with point as list[Point]; matching sampled points are sorted with the closest color first.

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, relative folder path, or a Template object in current macro.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
Optional · Positional or named
Default: 3.0

Returns

Match — Latest match state when the template disappears or timeout is reached.

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 or Template objects.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
Optional · Positional or named
Default: 3.0

Returns

MatchList — Batch match states when at least one template is no longer found.

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 or Template objects.
Required · Positional or named
No default
timeoutNumber
Maximum wait time in milliseconds. Omit this argument to scan only once.
Optional · Positional or named
Default: 0
thresholdNumber
Match threshold from 0.0 to 1.0.
Optional · Positional or named
Default: 0.7
rateNumber
Scan attempts per second (1-60).
Optional · Positional or named
Default: 3.0

Returns

MatchList — Batch match states when all templates are no longer found.

Example

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

Region.capture

Capture the screen and crop to this region, then return the result as a Template.

Syntax

region.capture(name=None)

Parameters

NameDescription
nameString?
Optional template name to save into current macro immediately.
Optional · Positional or named
Default: None

Returns

Template — Captured template object.

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
Shrink amount: 0 -> 1 means ratio of current width, >1 means pixels.
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
Shrink amount: 0 -> 1 means ratio of current width, >1 means pixels.
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
Shrink amount: 0 -> 1 means ratio of current height, >1 means pixels.
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
Shrink amount: 0 -> 1 means ratio of current height, >1 means pixels.
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 horizontal shrink: 0 -> 1 means ratio of current width, >1 means pixels.
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 vertical shrink: 0 -> 1 means ratio of current height, >1 means pixels.
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
Shrink amount for both axes: 0 -> 1 means ratio per axis, >1 means pixels per axis.
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 highlighted rectangle for this region. With movable=True, the user can drag the region and the same Region object receives the updated screen coordinates. Re-highlighting the same region instance replaces the previous one.

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
Stroke thickness in dp.
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

Turn off highlight for this region instance.

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()