跳到主要内容

MatchResult:getText()

返回与匹配项关联的标签或文本。

描述

getText() 方法返回与匹配结果关联的字符串标签。这在以下情况下特别有用:

  • 执行基于文本的搜索(OCR),返回识别到的文本
  • 使用带标签的模板,您希望识别匹配到的是哪个模板

如果该匹配项未关联标签,此方法返回空字符串。

签名

getText(): string

返回值

string - 与匹配项关联的标签或文本,如果没有则为空字符串。

示例

-- OCR 文本搜索示例
local result = Screen:find("hello World", FinderParams():setDetectionType("TEXT"))
if result then
local text = result:getText()
toast("Found text: " .. text)
end

-- 检查特定文本的示例
local result = Screen:find("submit", FinderParams():setDetectionType("TEXT"))
if result then
local label = result:getText()
if label == "submit" then
toast("Found submit button!")
end
end