[Lua] 纯文本查看 复制代码
local ocr, msg = createOCR({
type = "tesseract",
})
local function Mytext(a,b,c,d) --获取屏幕上的文字,a,b,c,d是对应的坐标
if ocr ~= nil then
local rect = {a,b,c,d}
local diff = {"0xffffff-0x0f0f0f"}
local code, text = ocr:getText({
rect = rect,
diff = diff
})
if code == 0 then
return text --返回读取的字符串
end
end
end
init("0",0)
setScreenScale(1080,1920)
local qq = 1 --全局变量,用于判断画面是否改变
for i = 1, 100 do --模仿continue,跳过本次循环
while true do
local texta5 = Mytext(492,489,594,568)
if qq ~= texta5 then --如果捕获到的画面与上次内容不同
qq = texta5 --赋值给全局变量
local texta = Mytext(204,750,471,944) --第一个数字
local texta3 = Mytext(608,765,930,951) --第二个数字
local texta4 = Mytext(303,961,779,1162) --结果
if getColor(544,818) == 0xffffff then --判断是加号还是减号
local result = texta + texta3
if(string.find(texta4,result) ~= nil) then --判断读取到的字符串是否包含正确答案
touchDown(0,318,1652)
mSleep(10)
touchUp(0,318,1652)
break
else
touchDown(0,815,1623)
mSleep(10)
touchUp(0,815,1623)
break
end
else
local result = texta - texta3
if(string.find(texta4,"-")) then --判断如果是减号,答案是否含有负号
if result >= 0 then --正确结果>0,却有负号,说明这道题答案是错的
touchDown(0,815,1623)
mSleep(10)
touchUp(0,815,1623)
break
else
touchDown(0,318,1652)
mSleep(10)
touchUp(0,318,1652)
break
end
end
if(string.find(texta4,result) ~= nil) then --判断读取到的字符串是否包含正确答案
touchDown(0,318,1652)
mSleep(10)
touchUp(0,318,1652)
break
else
touchDown(0,815,1623)
mSleep(10)
touchUp(0,815,1623)
break
end
end
else
break
end
end
end