Based on your input: "looks for given text on screen and clicks it using ocr"
#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GDIPlus.au3> ; You'll need to download and include the Tesseract OCR library #include "Tesseract.au3" ; This is a hypothetical include file for Tesseract OCR Func FindAndClickTextWithOCR($sText) ; Capture the entire screen Local $hBitmap = _ScreenCapture_Capture("") ; Initialize Tesseract OCR Local $hOCR = _Tesseract_Create() _Tesseract_SetImage($hOCR, $hBitmap) ; Perform OCR on the entire screen Local $sOCRText = _Tesseract_GetText($hOCR) ; Search for the given text in the OCR result Local $iPos = StringInStr($sOCRText, $sText) If $iPos > 0 Then ; Text found, now get its position Local $aPos = _Tesseract_GetWordBoxes($hOCR, $sText) If IsArray($aPos) And UBound($aPos) > 0 Then Local $iX = $aPos[0][0] + ($aPos[0][2] - $aPos[0][0]) / 2 Local $iY = $aPos[0][1] + ($aPos[0][3] - $aPos[0][1]) / 2 MouseClick("left", $iX, $iY, 1, 0) MsgBox($MB_ICONINFORMATION, "Success", "Text found and clicked: " & $sText) Else MsgBox($MB_ICONWARNING, "Error", "Text found but unable to determine its position.") EndIf Else MsgBox($MB_ICONWARNING, "Text Not Found", "Unable to find the text: " & $sText) EndIf ; Clean up _Tesseract_Destroy($hOCR) _GDIPlus_ImageDispose($hBitmap) EndFunc ; Main script _GDIPlus_Startup() Local $sTextToFind = InputBox("Find Text", "Enter the text to find on the screen:") If $sTextToFind Then FindAndClickTextWithOCR($sTextToFind) Else MsgBox($MB_ICONINFORMATION, "Cancelled", "Operation cancelled by user.") EndIf _GDIPlus_Shutdown()
This script provides a framework for finding and clicking text on the screen using OCR. Here's what it does:
OCR-based text recognition can be more reliable than pixel-based searches, especially for varying screen contents. However, it may be slower and require additional setup.