Skip to main content

Press-Key-in-Target

Command Description

Choose buttons in the specified interface element

Command Prototype

Keyboard.PressKey(objUiElement,sKey,iDelayBetweenKeys,iTimeOut,optionArgs)

Parameter Description

ParameterRequiredTypeDefaultDescription
objUiElementTruedecorator@ui""When the attribute is transferred as a string, it is used as the characteristic string to find the interface element. When the attribute is transferred as UiElement, directly click on the corresponding interface element
sKeyTrueenum"Enter"Correspond to the content to be entered in one simulation
iDelayBetweenKeysTruenumber20The interval between two input(only effective when Simulation operation is chosen in the attribute of operation type); If the interval is less than 20 milliseconds, it will be automatically converted to 20 milliseconds. If the interval is too short, it might lead to the word loss during the input. It is also affected by the machine performance
iTimeOutTruenumber10000Specify the amount of time (in milliseconds) that wait for the event to run before selectorNotFoundException to trigger an error (in milliseconds) The default value is 10,000 ms (10 seconds)
bContinueOnErrorNonebooleanNoneSpecify whether the automation should continue to support this field even if the activity is incorrect, it is only supported by the Boolean value (true, false) default value
iDelayAfterNonenumber300Delay time (in milliseconds) after executing the activity is 300 milliseconds
iDelayBeforeNonenumber500The delay time (in milliseconds in milliseconds) before the event is executed, and the amount of time is 500 milliseconds, too short may lead to leak input
bSetForegroundNonebooleanTrueWhether to activate the target window before executing
sKeyModifiersNoneset[]Keyboard keys used while a mouse action is triggered: Alt, Ctrl, Shift, Win
sSimulateNoneenum"simulate"You can choose Operation Type as: Background Operation (UIA), Simulation Operation (Simulate), System Message (MersSage), Default Selection: System Message (Message)
bClickBeforeInputNonebooleanNoneAfter finding the target, first click on the target and then enter the content

Demo

TracePrint "--------------------Press key in target--------------------" 
// --------------------------------------------------------
// [Remarks] Press the button in the target, this Demo is to simulate the "enter" button after entering "UiBot" in the Baidu search bar to realize the search function
// Input parameter 1:
// objUiElement--target element
// Input parameter 2:
// sKey--simulate keys
// Input parameter 3:
// iDelayBetweenKeys--type interval (ms)
// Input parameter 4:
// iTimeOut--timeout time. Default unit: milliseconds. Type: Int
// Input parameter 5:
// optionArgs--Optional parameters (including: error continue execution/delay after execution/delay before execution/activation window/auxiliary button/operation type/click before input).Type:Dict

// Command Prototype:Keyboard.PressKey(objUiElement,sKey,iDelayBetweenKeys,iTimeOut,optionArgs)
// --------------------------------------------------------

// Enter "UiBot" in the specified target
Keyboard.InputText(@ui"Input Controls<input>","UiBot",true,20,10000,{"bContinueOnError": false, "iDelayAfter": 300, "iDelayBefore": 500, "bSetForeground": true, "sSimulate": "message", "bValidate": false, "bClickBeforeInput": false})
// Simulate sending the "enter" key
Keyboard.PressKey(@ui"Input Controls<input>1","Enter",20,10000,{"bContinueOnError": false, "iDelayAfter": 300, "iDelayBefore": 200, "bSetForeground": true, "sSimulate": "simulate", "sKeyModifiers": [], "bClickBeforeInput": false})