Region API
Provides an API for querying the state of a region.
region.extract_text
Signatures
extract_text(region_name, opts \ [])
Description
Extract text from a specified region using pattern matching.
This function extracts text from a region that matches the given pattern. If no pattern is provided, it extracts all text from the region.
Options
pattern
- Regular expression pattern to match against detected text (default:.{1,}
- matches all text)case_sensitive
- Whether pattern matching is case sensitive (default: false)threshold
- Confidence threshold for text detection (default: 0)
Returns [success?, matched_text, detected_text]
where:
success?
- boolean indicating if text extraction was successfulmatched_text
- the text that matched the patterndetected_text
- all text detected in the region
Example
local success, matched, detected = region.extract_text("price_display", {
pattern = "\$[0-9]+\.[0-9]{2}",
case_sensitive = false
})
if success then
print("Price found: " .. matched)
end
region.is_active
Signatures
is_active(region, opts \ [])
Description
Check if a region is active, i.e., if it matches the intended content on the screen.
region.text_exists
Signatures
text_exists(region_name, opts \ [])
Description
Check if specific text exists within a region using pattern matching.
This function searches for text within a specified region using allow and reject patterns. At least one of allow_pattern or reject_pattern must be provided.
Options
allow_pattern
- Regular expression pattern that text must match to be considered validreject_pattern
- Regular expression pattern that will cause text to be rejected if matchedallow_case_sensitive
- Whether the allow pattern matching is case sensitive (default: false)reject_case_sensitive
- Whether the reject pattern matching is case sensitive (default: false)threshold
- Confidence threshold for text detection (default: 0)
Returns [exists?, matched_text, detected_text]
where:
exists?
- boolean indicating if matching text was foundmatched_text
- the specific text that matched the patterndetected_text
- all text detected in the region
Example
local exists, matched, detected = region.text_exists("login_button", {
allow_pattern = "Login|Sign In",
allow_case_sensitive = false
})
if exists then
print("Found login text: " .. matched[1])
end