get("#388") -- rect functions get("#428") -- findContents get("#430") -- makeIcon get("#433") -- iconDiff -- fw/fh: 8/17 cursor_unfocused = [[ RRRRRRRRRR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RAAAAAAAAR RRRRRRRRRR]] cursor_focused = "AAAAAAAAAA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.IRRRRRRRRA.ERRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.ARRRRRRRRA.AAAAAAAAAA" cursor_unfocused = cursor_unfocused:gsub("\n", ".") return function() problem = findContents() if problem then return problem end print("Searching cursor in "..contents_x1..", "..contents_y1..", "..contents_x2..", "..contents_y2) fw, fh = 8, 17 -- font width/height tw = math.floor((contents_x2-contents_x1)/fw+0.5) th = math.floor((contents_y2-contents_y1)/fh+0.5) tolerance = 0.01 local function recog(x, y) xx, yy = contents_x1+x*fw, contents_y1+y*fh-1 cropped = {width=fw+2, height=fh+2, getInt = function(x, y) return img.getInt(xx+x, yy+y) end} icon = makeIcon(cropped) diff = iconDiffWithLimit(icon, cursor_unfocused, tolerance, fw+2, fh+2) if diff ~= nil and diff <= tolerance then print("Cursor diff:", diff) lastCurX, lastCurY = x, y return "Cursor: "..xx..", "..yy..", ".. xx+cropped.width..", "..yy+cropped.height.. ". Cursor position: "..(x+1).."/"..(y+1).. ". Window not focused." end diff2 = iconDiffWithLimit(icon, cursor_focused, tolerance, fw+2, fh+2) --[[if y == 23 then print(x, y, diff, diff2) if x == 37 or x == 38 then print(icon) end end]] if diff2 ~= nil and diff2 <= tolerance then print("Cursor diff (focused):", diff2) lastCurX, lastCurY = x, y return "Cursor: "..xx..", "..yy..", "..xx+cropped.width..", "..yy+cropped.height..". Cursor position: "..(x+1).."/"..(y+1)..". Window focused." end end print("lastCur:", lastCurX, lastCurY) if lastCurX then local r = recog(lastCurX, lastCurY) if r then print("Cached cursor found!") return r end -- try whole line for x = 0, tw-1 do local r = recog(x, lastCurY) if r then return r end end end -- not found on cached line, try whole screen for y = 0, th-1 do if y ~= lastCurY then for x = 0, tw-1 do local r = recog(x, y) if r then return r end end end end return "Cursor not found" end