DeviceReplay Object
Description
An object used to simulate operations performed using a keyboard or mouse.
IMPORTANT
The DeviceReplay object is a UFT One reserved object. Reserved objects are not learned or stored in the object repository.
To use a DeviceReply object you need to create it using a CreateObject statement.
Set <Object Name>= CreateObject("Mercury.DeviceReplay")
When you no longer need the object in your test, release it.
Set <Object Name>= Nothing
Operations
The sections below list the built-in methods and properties that you can use as operations for the DeviceReplay object.
Methods
MouseClick | Clicks the mouse button at the specified screen location. |
MouseDblClick | Double-clicks the mouse button at the specified screen location. |
DragAndDrop | Presses the mouse in one location and releases it in another. |
PressKey | Presses and releases the specified keyboard key. |
PressNKeys | Presses the specified keyboard key a specified number of times. |
MouseDown | Presses the mouse button at the specified screen location. |
Moves the mouse pointer to the specified screen location. | |
MouseUp | Releases the mouse button at the specified screen location. |
KeyDown | Releases the mouse button at the specified screen location. |
KeyUp | Releases the specified keyboard key. |
SendString | Types a string. |
MouseClick Method
Description
Clicks the mouse button at the specified screen location.
Syntax
object.MouseClick x, y, [Button]
Arguments
Parameter | Description |
---|---|
x |
An integer value. The x-coordinate of the click, relative to the top left corner of the screen. |
y |
An integer value. The y-coordinate of the click, relative to the top left corner of the screen. |
Button |
Optional. A predefined constant or number. Possible values: 0 = LEFT_MOUSE_BUTTON (Default) 1 = MIDDLE_MOUSE_BUTTON 2 = RIGHT_MOUSE_BUTTON |
Return Type
None
Example
'The following example retrieves an object's location on the screen ' and uses the MouseClick method to click that location with an offset of 5X3 'because the object.Click was not working. x_coord = Window("Notepad").GetROProperty("abs_x") y_coord = Window("Notepad").GetROProperty("abs_y") Set deviceReplayObject= CreateObject("Mercury.DeviceReplay") deviceReplayObject.MouseClick x_coord + 5, y_coord + 3, LEFT_MOUSE_BUTTON
MouseDblClick Method
Description
Double-clicks the mouse button at the specified screen location.
Syntax
object.MouseDblClick x, y, [Button]
Arguments
Parameter | Description |
---|---|
x | An integer value. The x-coordinate of the double-click, relative to the top left corner of the screen. |
y |
An integer value. The y-coordinate of the double-click, relative to the top left corner of the screen. |
Button |
Optional. A predefined constant or number. Possible values: 0 = LEFT_MOUSE_BUTTON (Default) 1 = MIDDLE_MOUSE_BUTTON 2 = RIGHT_MOUSE_BUTTON |
Return Type
None
Example
'The following example retrieves an object's location on the screen ' and uses the MouseDblClick method to double-click that location with an offset of 6X4 'because the object.DblClick was not working. x_coord = Window("Notepad").GetROProperty("abs_x") y_coord = Window("Notepad").GetROProperty("abs_y") Set deviceReplayObject=CreateObject("Mercury.DeviceReplay") deviceReplayObject.MouseDblClick x_coord + 6, y_coord + 4, LEFT_MOUSE_BUTTON
Method
Description
Presses the mouse in one location and releases it in another.
Syntax
object.DragAndDrop DragX, DragY, DropX, DropY, [Button]
Arguments
Parameter | Description |
---|---|
DragX |
An integer value. The x-coordinate of the location to press the mouse, relative to the top left corner of the screen. |
DragY |
An integer value. The y-coordinate of the location to press the mouse, relative to the top left corner of the screen. |
DropX | An integer value. The x-coordinate of the location to release the mouse, relative to the top left corner of the screen. |
DropY |
An integer value. The y-coordinate of the location to release the mouse, relative to the top left corner of the screen. |
Button |
Optional. A predefined constant or number. Possible values: 0 = LEFT_MOUSE_BUTTON (Default) 1 = MIDDLE_MOUSE_BUTTON 2 = RIGHT_MOUSE_BUTTON |
Return Type
None
PressKey Method
Description
Presses and releases the specified keyboard key.
Syntax
object.PressKey Key
Arguments
Parameter | Description |
---|---|
Key | A numeric value. The decimal value of the key's IBM Scan Code. See Key Values. |
Return Type
None
Example
Const VK_CONTROL = 29
Const VK_A = 30
Const VK_C = 46
Window("Notepad++").Activate
Set myDeviceReplay = CreateObject("Mercury.DeviceReplay")
'Select all the file content and copy to clipboard
myDeviceReplay.KeyDown VK_CONTROL
myDeviceReplay.PressKey VK_A
myDeviceReplay.PressKey VK_C
myDeviceReplay.KeyUp VK_CONTROL
PressNKeys Method
Description
Presses the specified keyboard key a specified number of times.
Syntax
object.PressNKeys Key, N
Arguments
Parameter | Description |
---|---|
Key | A numeric value. The decimal value of the key's IBM Scan Code. See Key Values. |
N | A numeric value. |
Return Type
None
MouseDown Method
Description
Presses the mouse button at the specified screen location.
Syntax
object.MouseDown x, y, [Button]
Arguments
Parameter | Description |
---|---|
x |
An integer value. The x-coordinate of the location, relative to the top left corner of the screen. |
y | An integer value. The y-coordinate of the location, relative to the top left corner of the screen. |
Button |
Optional. A predefined constant or number. Possible values: 0 = LEFT_MOUSE_BUTTON (Default) 1 = MIDDLE_MOUSE_BUTTON 2 = RIGHT_MOUSE_BUTTON |
Return Type
None
Example
'The following example retrieves an object's location on the screen ' and uses the MousePress method to press the mouse's middle button 'at that location with an offset of 6X4 because the object.Click was not working. x_coord = Window("Notepad").GetROProperty("abs_x") y_coord = Window("Notepad").GetROProperty("abs_y") Set deviceReplayObject=CreateObject("Mercury.DeviceReplay") deviceReplayObject.MousePress x_coord + 6, y_coord + 4, MIDDLE_MOUSE_BUTTON
MouseMove Method
Description
Moves the mouse pointer to the specified screen location.
Syntax
object.MouseMove x, y
Arguments
Parameter | Description |
---|---|
x |
An integer value. The x-coordinate of the location, relative to the top left corner of the screen. |
y |
An integer value. The y-coordinate of the location, relative to the top left corner of the screen. |
Return Type
None
Example
'The following example retrieves an object's location on the screen ' and uses the MouseMove method to position the mouse at that location with an offset of 6X4. x_coord = Window("Notepad").GetROProperty("abs_x") y_coord = Window("Notepad").GetROProperty("abs_y") Set deviceReplayObject=CreateObject("Mercury.DeviceReplay") deviceReplayObject.MouseMove x_coord + 6, y_coord + 4
MouseUp
Description
Releases the mouse button at the specified screen location.
Syntax
object.MouseUp x, y, [Button]
Arguments
Parameter | Description |
---|---|
x |
An integer value. The x-coordinate of the location, relative to the top left corner of the screen. |
y |
An integer value. The y-coordinate of the location, relative to the top left corner of the screen. |
Button |
Optional. A predefined constant or number. Possible values: 0 = LEFT_MOUSE_BUTTON (Default) 1 = MIDDLE_MOUSE_BUTTON 2 = RIGHT_MOUSE_BUTTON |
Return Type
None
Example
'The following example retrieves an object's location on the screen ' and uses the MouseUp method to release the mouse middle button ' at that location with an offset of 6X4. x_coord = Window("Notepad").GetROProperty("abs_x") y_coord = Window("Notepad").GetROProperty("abs_y") Set deviceReplayObject=CreateObject("Mercury.DeviceReplay") deviceReplayObject.MouseUp x_coord + 6, y_coord + 4, MIDDLE_MOUSE_BUTTON
KeyDown Method
Description
Releases the mouse button at the specified screen location.
Syntax
object.KeyDown Key
Arguments
Parameter | Description |
---|---|
Key | A numeric value. The decimal value of the key's IBM Scan Code. See Key Values. |
Return Type
None
Example
Const VK_CONTROL = 29
Const VK_A = 30
Const VK_C = 46
Window("Notepad++").Activate
Set myDeviceReplay = CreateObject("Mercury.DeviceReplay")
'Select all the file content and copy to clipboard
myDeviceReplay.KeyDown VK_CONTROL
myDeviceReplay.PressKey VK_A
myDeviceReplay.PressKey VK_C
myDeviceReplay.KeyUp VK_CONTROL
KeyUp Method
Description
Releases the specified keyboard key.
Syntax
object.KeyUp Key
Arguments
Parameter | Description |
---|---|
Key | A numeric value. The decimal value of the key's IBM Scan Code. See Key Values. |
Return Type
None
Example
Const VK_CONTROL = 29
Const VK_A = 30
Const VK_C = 46
Window("Notepad++").Activate
Set myDeviceReplay = CreateObject("Mercury.DeviceReplay")
'Select all the file content and copy to clipboard
myDeviceReplay.KeyDown VK_CONTROL
myDeviceReplay.PressKey VK_A
myDeviceReplay.PressKey VK_C
myDeviceReplay.KeyUp VK_CONTROL
'get the text from the clipboard
Dim textContent
textContent = CreateObject("htmlfile").ParentWindow.ClipboardData.Getdata("text")
'Create a regular expression to find specific content according to its prefix and postfix
Set RegularExoressionObject = New RegExp
With RegularExoressionObject .Pattern = "Prefix(.*)Postfix"
.IgnoreCase = True
.Global = False
End
With Set objMatch = RegularExoressionObject.Execute( textContent )
' Retrieve a unique match
txt = "empty"
If objMatch.Count = 1 Then
txt = objMatch.Item(0).submatches(0)
print txt
msgbox txt
End If
SendString Method
Description
Types a string.
Syntax
object.SendString wStr
Arguments
Parameter | Description |
---|---|
wStr | A String value.
The string to type.
|
Return Type
None
Key Values
For DeviceReplay operations that receive keyboard keys as arguments, use the following key values. These are the decimal values of the keys' IBM Scan Codes.
Key | Value | Key | Value |
---|---|---|---|
A | 30 | ` | 41 |
B | 48 | - | 12 |
C | 46 | = | 13 |
D | 32 | \ | 43 |
E | 18 | BKSP | 14 |
F | 33 | TAB | 15 |
G | 34 | L SHFT | 42 |
H | 35 | L CTRL | 29 |
I | 23 | L ALT | 56 |
J | 36 | R SHFT | 54 |
K | 37 | R CTRL | 157 |
L | 38 | R ALT | 184 |
M | 50 | ENTER | 28 |
N | 49 | ESC | 1 |
O | 24 | SCROLL | 70 |
P | 25 | [ | 26 |
Q | 16 | ] | 27 |
R | 19 | INSERT | 210 |
S | 31 | HOME | 199 |
T | 20 | PG UP | 201 |
U | 22 | DELETE | 211 |
V | 47 | END | 207 |
W | 17 | PG DN | 209 |
X | 45 | U ARROW | 200 |
Y | 21 | L ARROW | 203 |
Z | 44 | D ARROW | 208 |
0 | 11 | R ARROW | 205 |
1 | 2 | ; | 39 |
2 | 3 | ' | 40 |
3 | 4 | , | 51 |
4 | 5 | . | 52 |
5 | 6 | / | 53 |
6 | 7 | Keypad / | 181 |
7 | 8 | Keypad * | 55 |
8 | 9 | Keypad - | 74 |
9 | 10 | Keypad + | 78 |
SPACE | 57 | Keypad EN | 156 |
CAPS | 58 | Keypad . | 83 |
F1 | 59 | Keypad 0 | 82 |
F2 | 60 | Keypad 1 | 79 |
F3 | 61 | Keypad 2 | 80 |
F4 | 62 | Keypad 3 | 81 |
F5 | 63 | Keypad 4 | 75 |
F6 | 64 | Keypad 5 | 76 |
F7 | 65 | Keypad 6 | 77 |
F8 | 66 | Keypad 7 | 71 |
F9 | 67 | Keypad 8 | 72 |
F10 | 68 | Keypad 9 | 73 |
F11 | 87 | ||
F12 | 88 | ||
NUM | 69 |
See also:
- Crypt Object
- DataTable Object
- Description Object
- DeviceReplay Object
- DotNetFactory Object
- DTParameter Object
- DTSheet Object
- Environment Object
- Extern Object
- Parameter Object
- JSON Object
- JsonUtil Object
- MercuryTimers Object (Collection)
- MercuryTimer Object
- NV Object
- OptionalStep Object
- ParallelUtil Object
- LocalParameter Object
- PasswordUtil Object
- PathFinder Object
- PDFUtil Object
- Properties Object (Collection)
- QCUtil Object
- RandomNumber Object
- Recovery Object
- Remote Connection Object
- Reporter Object
- RepositoriesCollection Object
- Repository Object
- Services Object
- Setting Object
- SystemMonitor Object
- TestArgs Object
- TextUtil Object
- UIAutomation Object
- VisualRelation Object
- VisualRelations Object
- VisualRelationsCollection Object
- WebUtil Object
- XMLUtil Object