Description
Use the SendKeys
action to simulate keyboard input to the screen area that is at the specified distance and in the specified position relative to the text block recognized by the optical character recognition (OCR) engine.
Declaration
TestObj.SendKeys(Keys, Direction, Offset)
TestObj | A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section | |||
Keys | [in] | Required | String | |
Direction | [in] | Required | Integer | |
Offset | [in] | Required | Integer | |
Result | None |
Applies To
The method is applied to the following object:
View Mode
This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.
Parameters
The method has the following parameters:
Keys
Specifies the keystroke to be simulated.
To simulate the pressing of system keys, such as Ctrl, Alt, Shift, F1, Tab and others, use the following constants:
|
|
All constants (F1 , PageDown , X , P , etc.) are case-sensitive. |
Shift codes (^, ~ and !) in the Keys parameter do not press Ctrl, Alt or Shift. Instead, the next key in the string will be pressed under the indicated shift conditions. That is, the shift codes influence on the first non-shift key that follows them in the Keys string. For instance, the following code presses Ctrl+ESC (this shortcut shows the Start menu):
To separate shift-key presses from combined key presses like the above, use two consecutive calls of the Keys
method. For example, the following code first presses Ctrl and then ESC (this operation does not call the Start menu, since the key presses are separated). Another way to achieve this effect is to use the [Release]
constant (more below).
To simulate simultaneous pressing of several keys, use the [Hold]
constant. For instance, [Hold][Win]e
will launch Windows Explorer.
To deactivate [Hold]
, use the [Release]
and [ReleaseLast]
constants. [ReleaseLast]
signals to TestComplete that it should simulate the releasing of the last pressed key. For instance, the string [Hold]^f[ReleaseLast]U
indicates the following sequence of keypresses: pressing of Ctrl, pressing of f, releasing of f, pressing of U, releasing of U and Ctrl.
[Release]
simulates the release of all pressed keys. For example, the string [Hold]^fU[Release]
(or [Hold]^fU
) indicates that TestComplete should press Ctrl, then press f, then press U and then release all these keys.
You can also simulate a keystroke using virtual-key code of the desired character. To do this, use the X
or D
tags. X
simulates pressing of a key with the specified code using the current keyboard layout. D
is typically used for simulating dead-key characters (accent or diacritic). This feature is especially useful if you need to type some national characters (for instance, a
with circumflex). When the Keys
method finds the D
tag, it checks whether the specified key is supported by keyboard layouts installed in the operating system. If the check is successful, the method switches the keyboard layout to the appropriate layout and then simulates the keystroke. Else, the tag is ignored.
The X
and D
tags can be used along with Ctrl, Alt and Shift constants. For instance, [D221]a
will simulate a
with circumflex, [D221]!a
- A
with circumflex.
Direction
Specifies the position of the target screen area, which is relative to the recognized text block. The allowed parameter values are:
Value | Description |
---|---|
toLeft |
The target screen area is located to the left of the text block. |
toTop |
The target screen area is located above the text block. |
toRight |
The target screen area is located to the right of the text block. |
toBottom |
The target screen area is located below the text block. |
Offset
Specifies the distance between the point at which you want to simulate user actions and the text block’s border that is closest to the point. For instance, if the target point is located to the right of the text block, the Offset parameter specifies the distance between the block’s left border and the point.
Result Value
None.
Example
To view an example that demonstrates how to use the SendKeys
action, see Get Controls With No Text Contents.
See Also
Get Controls With No Text Contents
OCRTextBlock Object Methods
OCRTextBlock Object
Optical Character Recognition
ClickNextTo Action
TouchNextTo Action