Skip to main content
Version: v6.5.0

Screen OCR recognition

Command Description

Use the OCR identification screen to specify the range. When calling, you need to access the Internet

Command Prototype

sText = OCR.ScreenOCR(objElement,objRect,sEngine,sAcessKey,sSecretKey,iTimeOut,optionArgs)

Command parameter

parametermandatorytypedefault valueInstructions
objElementTruedecorator@ ui""Corresponding to the UI elements to be operated, when the attribute is passed as a string type, the UI elements is searched as a feature string. When the attribute is passed as a UiElement type, the UI elements corresponding to the UiElement is directly clicked
objRectTruedictionary{"x":0,"y":0,"width":0,"height":0}The program will perform OCR text recognition within the range of the control. If the range is passed as {"x": 0, "y": 0, "width": 0, "height": 0}, then text recognition will be performed within the rectangular area of the control
sEngineTrueenum"baidu1"OCR engine used for text recognition
sAcessKeyTruestring""ApiKey for OCR Services
sSecretKeyTruestring""Secret Key for OCR Service
iTimeOutTruenumberten thousandSpecifies the amount of time (in milliseconds) to wait for the Activity to run before the SelectorNotFoundException throws an exception. The default value is 10000 milliseconds (10 seconds)
bContinueOnErrorFalsebooleanFalseSpecifies whether automation should continue even if the Activity raises an error. This field only supports Boolean values (True, False). The default value is False
iDelayAfterFalsenumberthree hundredThe delay time (in milliseconds) after the execution of the Activity. The default time is 300 milliseconds
iDelayBeforeFalsenumbertwo hundredThe delay in milliseconds before the Activity starts performing any action. The default time limit is 200 milliseconds
bSetForegroundFalsebooleanTrueBefore performing the operation, should the target window be activated first

Return result

SText, Assign the result of running the command to this variable.

Run instance

/**************************Screen OCR Recognition**************************
Command prototype:
sText = OCR.ScreenOCR(@ui"", {"x":0, "y":0, "width":0, "height":0}, "baidu", "", "", 10000, {"bContinueOnError":false, "iDelayAfter":300, "iDelayBefore":200, "bSetForeground":true})
Input parameters:
objUiElement -- Recognition target.
objRect -- Target recognition range. Default value: {"x":0, "y":0, "width":0, "height":0}
sEngine -- OCR engine. Note: The OCR engine used.
sAccessKey -- Baidu OCR engine ApiKey. Note: ApiKey for OCR service (need to register OCR account and create application to get this parameter).
sSecretKey -- Baidu OCR engine SecretKey. Note: SecretKey for OCR service (need to register OCR account and create application to get this parameter).
iTimeOut -- Timeout. Note: The amount of time (in milliseconds) to wait for the activity to run before SelectorNotFoundException is thrown. The default value is 10000 milliseconds (10 seconds).
optionArgs -- Optional parameters (including: continue execution on error, delay after execution, delay before execution, activate window, cursor position, horizontal offset, vertical offset, auxiliary keys, operation type). Type: Dict.
Output parameters:
sText -- The variable where the output of the function call is saved.
Notes:
1. This command calls the external Baidu OCR interface. You need to create a Baidu OCR account and corresponding application in advance, and obtain the corresponding Access Key and Secret Key of the application.
2. An external network connection is required to run this command.
******************************************************************/

Dim sText = ""
sText = OCR.ScreenOCR(@ui"文本<span>_ScreenOCR",{"x":0,"y":0,"width":0,"height":0},"baidu1","P10qsjDcuoN5ZU7dnSHmXzGh","Fm8whYrNnXtKkSvqVPUYL573XfNbxlmO",10000,{"bContinueOnError":false,"iDelayAfter":300,"iDelayBefore":200,"bSetForeground":true})
TracePrint(sText)