Home > Language Reference > Windows Management Functions > ClickOnTextOCR


The ClickOnTextOCR function clicks on the specified text recognized by OCR engine (or near it).


Used to click on an image that includes some text. The only way to obtain text shown in an image is to use the OCR engine. ClickOnBitmap function can click too on the image but it is too dependant on screen resolution.

Video: How to use ClickOnTextOCR for right clicking a text recognized through MODI or WinTask x64 OCR engine.


 ret=ClickOnTextOCR(<text>, left|right,single|double, InArea(<x>,<y>,<height>,<width>) [,<offset_x>,<offset_y> [,<language>]])


<text>, string, text to click. 

left|right, keyword, type of mouse button to click.

single|double, keyword indicating the click action.

InArea, keyword. It specifies the zone where the text is searched.

<x>,<y>, integer, coordinates of the topleft point of the area.

<height>,<width>, integer, size of the area.

<offset_x>,<offset_y>, optional integers specifying an offset distance for the click. If not specified, the click is done on the middle of the image.

<language>, optional string, constant, language used by the OCR engine. WinTask x64 OCR engine can only use English language. MODI OCR engine uses the default Microsoft Office™ language if <language> is not specified.

Return value

ret, optional numeric return value. During the time delay specified by #ActionTimeout, the OCR engine captures the screen portion specified in InArea, converts the image in text and tries to find <text> in the window specified by the last UseWindow statement and clicks. If the function succeeds, the return value is 0. If the text is not found by the OCR engine in the specified area, the return value is 1 (see Windows Management Functions Error Codes for the other possible return values).

Script execution does NOT stop in case of an error while executing ClickOnTextOCR.


Generate the ClickOnTextOCR syntax using its wizard: in the Language pane of the WinTask x64 Editor, double-click the ClickOnTextOCR function name to start the wizard (if the Language pane is not displayed, press F4 or select Insert/Statement menu).

The default OCR engine used by ClickOnTextOCR is the WinTask x64 OCR engine. With this engine, the click at replay is done in the middle of the rectangle specified in the ClickOnTextOCR function.
If the MODI OCR engine is used, the click at replay is done on the exact word as specified in <text> parameter. You can force the use of MODI OCR engine by adding the line UseOCREngine(1) before the ClickOnTextOCR call (the ClickOnTextOCR wizard generates this line automatically). 

See also

How to install MODI OCR engine


'ClickOnTextOCR clicks "combination" word in the sentence "Automate any combination of tasks"
StartBrowser("IE", "
'Ensure that the Macro page is loaded using UsePage
'If UseOCREngine is not assigned, the default OCR engine is used, the WinTask one
'TopInstance() as last parameter of UseWindow looks for the instance of IE on the top
UseWindow("IEXPLORE.EXE|Internet Explorer_Server|Macro|1",topinstance())
'With WinTask OCR engine, only combina is correclty rendered by the OCR engine, so the ClickOnTextOCR uses only these characters
 ClickOnTextOCR("combina", left, single, InArea(397, 375, 93, 19))

'Using MODI OCR engine, those lines click the Download your 30-day trial now! button at the "your" word.
StartBrowser("IE", "
'Use MODI OCR engine
ret = UseOCREngine(1)
'TopInstance() as last parameter of UseWindow looks for the instance of IE on the top
UseWindow("IEXPLORE.EXE|Internet Explorer_Server|Macro|1",TopInstance())
'Click the "your" word in the red button DOWNLOAD your 30-day trial now!
 ClickOnTextOCR("your ", left, single, InArea(1008, 547, 25, 22))