Login   /   Register

The Undocumented DeviceReplay

Rate this article
     7 votes, average: 4.43 out of 57 votes, average: 4.43 out of 57 votes, average: 4.43 out of 57 votes, average: 4.43 out of 57 votes, average: 4.43 out of 5
Loading ... Loading ...
April 4th, 2008 by Yaron Assa

Google Search Results

You arrived here after searching for the following phrases:

Click a phrase to jump to the first occurrence, or return to the search results.

 

Somehow HP help files do not provide information about this powerful feature.

You can find DeviceReplay property under Java add-in, but for those who doesn’t use Java add-in might think that the feature is not available for them.

Why Device Replay?

Sometimes we need to do specific action on the UI, for example a right click on an object, use Fx keys to activate some hotkey, or just when object.Set and object.Type methods, somehow doesn’t work for you.

Also it can be useful to type symbols and letters from different languages, without installing special fonts or changing the keyboard layout, and this can be very usefull for testing multi-language applications.

For mouse operation i found very useful the DragDrop method, to drag and drop items from one frame to another or between applications.


The deviceReplay object is used to simulate mouse clicks and movements and also keyboard input. To use DeviceReplay you must ensure that your AUT is the active window. If you want to perform an action on a object, the object must have the focus. For Windows applications you can use the Activate method

Window( "W" ).Activate micLeftBtn

To set the focus on a specific object in windows, usually the Click method will do the job.

For web environment applications the Activate method is not supported, so yo can use the following trick :

hwnd = Browser( "B" ).GetROProperty( "hwnd" )

Window( "hwnd:=" & hwnd ).Activate micLeftBtn

To set the focus on any object usually the FireEvent “onfocusin” or object.focus e.g.

WebEdit( "WE" ).object.focus or WebEdit( "WE" ).FireEvent "onfocusin"

For accessing the device replay methods you need first to create the devicereplay object

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

Why do i introduce this .NET class with the DeviceReplay object?

DeviceReplay is a really powerful undocumented object but has limitations.

One of the limitations is to determine if a control key is already pressed.

before we want to print a capital letter, we want to know if CAPS-LOCK already pressed. Before we use the numpad we want to verify that if NUM-LOCK already pressed. Otherwise we’ll just toggle the state, to maybe an unwanted state.

The Devices.Keyboard class Provides properties for accessing the current state of the keyboard, such as what keys are currently pressed, and provides a method to send keystrokes to the active window.

The required properties for our purpose are

clip_image003       AltKeyDown - Gets a Boolean indicating if the ALT key is down.

clip_image003       CapsLock - Gets a Boolean indicating if CAPS LOCK is turned on. 

clip_image003       CtrlKeyDown - Gets a Boolean indicating if a CTRL key is down.

clip_image003       NumLock - Gets a Boolean indicating if the NUM LOCK key is on. 

clip_image003       ScrollLock - Gets a Boolean indicating whether the SCROLL LOCK key is on. 

clip_image003       ShiftKeyDown - Gets a Boolean indicating if a SHIFT key is down.

Set Keyboard = DotNetFactory.CreateInstance( "Microsoft.VisualBasic.Devices.Keyboard", "Microsoft.VisualBasic" )

Print CBool( Keyboard.AltKeyDown )

Print CBool( Keyboard.CapsLock )

Print CBool( Keyboard.CtrlKeyDown )

Print CBool( Keyboard.NumLock )

Print CBool( Keyboard.ScrollLock )

Print CBool( Keyboard.ShiftKeyDown )

Important! When Using DotNetFactory data types must be converted.

System.Windows.Forms.Control Class

Another useful feature is to retrieve the current mouse ( cursor ) position in the screen according to the limitation of the DeviceReplay object.

The System.Windows.Forms.Control base Class Defines the base class for controls, which are components with visual representation.

the MousePosition property Gets the position of the mouse cursor in screen coordinates. The MousePosition property returns a Point that represents the mouse cursor position at the time the property was referenced.

Where is my mouse?

Set ctlr = DotNetFactory.CreateInstance("System.Windows.Forms.Control")

For i = 1 To 10

   Wait 2

   Print "1. X=" & ctlr.MousePosition.X & "; Y=" & ctlr.MousePosition.Y

Next

Mercury.DeviceReplay Methods

SendString Method

clip_image005

 

Sends one or more keystrokes to the active window, as if typed on the keyboard.

clip_image007

 

object.SendString( str )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

str

the String to be typed

clip_image011

 

None

clip_image013

 

The Following example will activate notepad and type a string.

 

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

SystemUtil.Run "notepad.exe", "", "", "open"

' ** this line always identifies the notepad window.

Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn

deviceReplay.SendString( "DeviceReplay" )

Set deviceReplay = Nothing

KeyDown Method

clip_image005

 

Simulates a key press and hold via keyboard ( KEY_DOWN event in Win32 )

clip_image007

 

object.KeyDown( key )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

key

the key numeric code for more information on key codes see Key Codes Reference

clip_image011

 

None

clip_image013

 

The Following example will activate notepad and type a string in uppercase and lowercase in a new line. Note that the shift key remains pressed while sending the first string.

 

Const VK_SHIFT = 42

Const VK_RETURN = 28

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

SystemUtil.Run "notepad.exe", "", "", "open"

Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn

' ** Typing uppercase

deviceReplay.KeyDown VK_SHIFT

deviceReplay.SendString( "devicereplay" )

deviceReplay.PressKey VK_RETURN

deviceReplay.KeyUp VK_SHIFT

' ** Typing in lower case

deviceReplay.SendString( "devicereplay" )

Set deviceReplay = Nothing

clip_image015

 

clip_image001        Since the key remains pressed use always the KeyUp Method.

clip_image001        The method is just like human presses a key and left it pressed all the time.

KeUp Method

clip_image005

 

Simulates a key released via keyboard.

clip_image007

 

object.KeyUp( key )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

key

the key numeric code for more information on key codes see Key Codes Reference

clip_image011

 

None

clip_image013

 

The Following example will activate the open menu of notepad using the hotkey Ctrl+O and will close it using Escape.

 

Const VK_O = 24

Const VK_CONTROL = 29

Const VK_ESCAPE = 1

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

SystemUtil.Run "notepad.exe", "", "", "open"

Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn

' ** Typing uppercase

Wait 1

' ** Opening the menu Ctrl + O

deviceReplay.KeyDown VK_CONTROL

deviceReplay.PressKey VK_O

deviceReplay.KeyUp VK_CONTROL

Wait 2

' ** Closing the menu

deviceReplay.PressKey VK_ESCAPE

deviceReplay.SendString "Menu Open, was closed."

Set deviceReplay = Nothing

clip_image015

 

clip_image001        Use always KeyUp Method after the KeyDown.

clip_image001        Multiple KeyUp keys does not affect the application.

clip_image001        When you need to combine a hotkey, just treat the events like as a human would do it.

PressKey Method

clip_image005

 

Simulates a key pressed and immediately released via keyboard.

clip_image007

 

object.PressKey( key )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

key

the key numeric code for more information on key codes see Key Codes Reference

clip_image011

 

None

clip_image013

 

The Following example will activate the open menu of notepad using the hotkey Ctrl+O and will close it using Escape.

 

Const VK_O = 24 : Const VK_F = 33

Const VK_CONTROL = 29 : Const VK_ESCAPE = 1 : Const VK_MENU = 56

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

SystemUtil.Run "notepad.exe", "", "", "open"

Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn

Wait 1

' ** Opening the menu Alt + F + O

deviceReplay.PressKey VK_MENU

deviceReplay.PressKey VK_F

deviceReplay.PressKey VK_O

Wait 2

' ** Closing the menu

deviceReplay.PressKey VK_ESCAPE

deviceReplay.SendString "Open menu was closed."

Set deviceReplay = Nothing

PressNKeys Method

clip_image005

 

Simulates a key pressed and immediately released several times via keyboard.

clip_image007

 

object.PressNKey( key, N )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

key

the key numeric code for more information on key codes see Key Codes Reference

 

N

The number of repetitions.

clip_image011

 

None

Examples

Example 1 - States of USA

Option Explicit

 

Const VK_RETURN = 28 : Const VK_F = 33 : Const VK_O = 24

Const VK_TAB = 15 : Const VK_F5 = 63

Const VK_CAPITAL = 58 : Const VK_NUMLOCK = 69

Const VK_SUBTRACT = 74 : Const VK_MULTIPLY = 55

Const VK_MENU = 56

 

Dim deviceReplay

 

Private Sub SetupKeyboard()

   Const CLASS_NAME = "Microsoft.VisualBasic.Devices.Keyboard"

   Const ASSEMBLY = "Microsoft.VisualBasic"

   Dim Keyboard

     

   Set Keyboard = DotNetFactory.CreateInstance( CLASS_NAME, ASSEMBLY )

   If CBool( Keyboard.CapsLock ) Then

      deviceReplay.PressKey VK_CAPITAL

   End If

   If CBool( Keyboard.NumLock ) = False Then

   deviceReplay.PressKey VK_NUMLOCK

   End If

   Set Keyboard = Nothing

End Sub

 

Private Sub SetupNotepad()

   deviceReplay.PressKey VK_MENU

   deviceReplay.PressKey VK_O

   deviceReplay.PressKey VK_F

   deviceReplay.SendString "Courier New"

   deviceReplay.PressKey VK_TAB

   deviceReplay.PressKey VK_TAB

   deviceReplay.SendString "14″

   deviceReplay.PressKey VK_RETURN

   Wait 1

End Sub

 

Private Sub PrintRow( ByVal state, ByVal usps, byVal capital )

   deviceReplay.SendString state

   deviceReplay.PressKey VK_TAB

   If Len( state ) < 8 Then

      deviceReplay.PressKey VK_TAB

   End If

   deviceReplay.SendString usps

   deviceReplay.PressKey VK_TAB

   deviceReplay.SendString capital

   deviceReplay.PressKey VK_RETURN

End Sub

 

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

SystemUtil.Run "notepad.exe", "", "", "open", 3

Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn

' ** Setup Notepad - Font courier new, size 14,

' ** NUM-LOCK pressed and CAPS-LOCK unpressed

Call SetupKeyboard()

Call SetupNotepad()

' ** inserting date

deviceReplay.PressKey VK_F5

deviceReplay.PressKey VK_RETURN

' ** Inserting Title

deviceReplay.PressNKeys VK_TAB, 3

deviceReplay.SendString "United States of America"

deviceReplay.PressKey VK_RETURN

deviceReplay.PressNKeys VK_TAB, 3

deviceReplay.PressNKeys VK_MULTIPLY, Len( "United States of America" )

deviceReplay.PressNKeys VK_RETURN, 2

' ** Table Headers

deviceReplay.SendString "State"

deviceReplay.PressKey VK_TAB

deviceReplay.PressKey VK_TAB

deviceReplay.SendString "USPS"

deviceReplay.PressKey VK_TAB

deviceReplay.SendString "Capital"

deviceReplay.PressKey VK_RETURN

deviceReplay.PressNKeys VK_SUBTRACT, 31

deviceReplay.PressKey VK_RETURN

' ** Print Data

Call PrintRow( "Alabama", "AL", "Montgomery" )

Call PrintRow( "Alaska", "AK", "Juneau" )

Call PrintRow( "Arizona", "AZ", "Phoenix" )

Call PrintRow( "Arkansas", "AR", "Little Rock" )

Call PrintRow( "California", "CA", "Sacramento" )

Call PrintRow( "Colorado", "CO", "Denver" )

Call PrintRow( "Connecticut", "CT", "Hartford" )

Call PrintRow( "Delaware", "DE", "Dover" )

Call PrintRow( "Florida", "FL", "Tallahassee" )

Call PrintRow( "Georgia", "GA", "Atlanta" )

Call PrintRow( "Hawaii", "HA", "Honolulu" )

Call PrintRow( "Idaho", "ID", "Boise" )

Call PrintRow( "Illinois", "IL", "Springfield" )

Call PrintRow( "Indiana", "IN", "Indianapolis" )

Call PrintRow( "Iowa", "IA", "Des Moines" )

Call PrintRow( "Kansas", "KS", "Topeka" )

Call PrintRow( "Kentucky", "KY", "Frankfort" )

Call PrintRow( "Louisiana", "LA", "Baton Rouge" )

Call PrintRow( "Maine", "ME", "Augusta" )

Call PrintRow( "Maryland", "MD", "Annapolis" )

Call PrintRow( "Massachusetts", "MA", "Boston" )

Call PrintRow( "Michigan", "MI", "Lansing" )

Call PrintRow( "Minnesota", "MN", "Saint Paul" )

Call PrintRow( "Mississippi", "MS", "Jackson" )

Call PrintRow( "Missouri", "MO", "Jefferson City" )

Call PrintRow( "Montana", "MT", "Helena" )

Call PrintRow( "Nebraska", "NE", "Lincoln" )

Call PrintRow( "Nevada", "NV", "Carson City" )

Call PrintRow( "New Hampshire", "NH", "Concord" )

Call PrintRow( "New Jersey", "NJ", "Trenton" )

Call PrintRow( "New Mexico", "NM", "Santa Fe" )

Call PrintRow( "New York", "NY", "Albany" )

Call PrintRow( "North Carolina", "NC", "Raleigh" )

Call PrintRow( "North Dakota", "ND", "Bismarck" )

Call PrintRow( "Ohio", "OH", "Columbus" )

Call PrintRow( "Oklahoma", "OK", "Oklahoma City" )

Call PrintRow( "Oregon", "OR", "Salem" )

Call PrintRow( "Pennsylvania", "PA", "Harrisburg" )

Call PrintRow( "Rhode Island", "RI", "Providence" )

Call PrintRow( "South Carolina", "SC", "Columbia" )

Call PrintRow( "South Dakota", "SD", "Pierre" )

Call PrintRow( "Tennessee", "TN", "Nashville" )

Call PrintRow( "Texas", "TX", "Austin" )

Call PrintRow( "Utah", "UT", "Salt Lake City" )

Call PrintRow( "Vermont", "VT", "Montpelier" )

Call PrintRow( "Virginia", "VA", "Richmond" )

Call PrintRow( "Washington", "WA", "Olympia" )

Call PrintRow( "West Virginia", "WV", "Charleston" )

Call PrintRow( "Wisconsin", "WI", "Madison" )

Call PrintRow( "Wyoming", "WY", "Cheyenne" )

 

Set deviceReplay = Nothing

Example 2 - Latin characters and Symbols

Option Explicit

 

Const VK_NUMPAD0 = 82

Const VK_NUMPAD1 = 79

Const VK_NUMPAD2 = 80

Const VK_NUMPAD3 = 81

Const VK_NUMPAD4 = 75

Const VK_NUMPAD5 = 76

Const VK_NUMPAD6 = 77

Const VK_NUMPAD7 = 71

Const VK_NUMPAD8 = 72

Const VK_NUMPAD9 = 73

Const VK_MENU = 56

Const VK_SHIFT = 42

Const VK_RETURN = 28

Const VK_F = 33

Const VK_O = 24

Const VK_TAB = 15

Const VK_F5 = 63

Const VK_NUMLOCK = 69

Dim deviceReplay

 

Private Sub SetupKeyboard()

   Const CLASS_NAME = "Microsoft.VisualBasic.Devices.Keyboard"

   Const ASSEMBLY = "Microsoft.VisualBasic"

   Dim Keyboard

     

   Set Keyboard = DotNetFactory.CreateInstance( CLASS_NAME, ASSEMBLY )

   If CBool( Keyboard.CapsLock ) Then

      deviceReplay.PressKey VK_CAPITAL

   End If

   If CBool( Keyboard.NumLock ) = False Then

   deviceReplay.PressKey VK_NUMLOCK

   End If

   Set Keyboard = Nothing

End Sub

 

Private Sub SetupNotepad()

   deviceReplay.PressKey VK_MENU

   deviceReplay.PressKey VK_O

   deviceReplay.PressKey VK_F

   deviceReplay.SendString "Courier New"

   deviceReplay.PressKey VK_TAB

   deviceReplay.PressKey VK_TAB

   deviceReplay.SendString "14″

   deviceReplay.PressKey VK_RETURN

   Wait 1

End Sub

 

Private Sub PrintCharacter( ByVal code )

   Dim i, digit

 

   deviceReplay.KeyDown VK_MENU

   For i = 1 To Len( code )

      digit = Mid( code, i, 1 )

      Execute "deviceReplay.PressKey VK_NUMPAD" & digit

   Next

   deviceReplay.KeyUp VK_MENU

   deviceReplay.PressKey VK_RETURN

End Sub

 

Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

SystemUtil.Run "notepad.exe", "", "", "open", 3

Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn

' ** Setup Notepad - Font courier new, size 14,

' ** NUM-LOCK pressed and CAPS-LOCK unpressed

Call SetupKeyboard()

Call SetupNotepad()

' ** inserting date

deviceReplay.PressKey VK_F5

deviceReplay.PressKey VK_RETURN

' ** a grave character

deviceReplay.SendString "A grave: "

Call PrintCharacter( "0192″ )

' ** O circumflex character

deviceReplay.SendString "O circumflex: "

Call PrintCharacter( "0212″ )

' ** s caron character

deviceReplay.SendString "s caron: "

Call PrintCharacter( "0154″ )

' ** n tilde character

deviceReplay.SendString "n tilde: "

Call PrintCharacter( "164″ )

' ** Y umlaut character

deviceReplay.SendString "Y umlaut: "

Call PrintCharacter( "0159″ )

' ** c cedila character

deviceReplay.SendString "c cedila: "

Call PrintCharacter( "0231″ )

' ** O with accent character

deviceReplay.SendString "O with accent: "

Call PrintCharacter( "0211″ )

' ** Inverted question mark character

deviceReplay.SendString "Inverted question mark: "

Call PrintCharacter( "168″ )

' ** Euro character

deviceReplay.SendString "Euro: "

Call PrintCharacter( "0128″ )

' ** i with accent character

deviceReplay.SendString "i with accent : "

Call PrintCharacter( "0237″ )

' ** Male Sign character

deviceReplay.SendString "Male Sign: "

Call PrintCharacter( "11″ )

' ** AE ligature  character

deviceReplay.SendString "AE ligature: "

Call PrintCharacter( "0198″ )

' ** aa  character

deviceReplay.SendString "aa: "

Call PrintCharacter( "0197″ )

' ** oethel  character

deviceReplay.SendString "oethel: "

Call PrintCharacter( "0156″ )

' ** Eth  character

deviceReplay.SendString "Eth: "

Call PrintCharacter( "0208″ )

' ** Uppercase Sigma character

deviceReplay.SendString "Uppercase Sigma: "

Call PrintCharacter( "228″ )

 

Set deviceReplay = Nothing

DragAndDrop Method

clip_image005

 

Method performs a drag and drop action from one point to another

clip_image007

 

object.DragAndDrop( dragX, dragY, dropX, dropY, Button )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

dragX

the x absolute coordinate in a screen for start dragging

 

dragY

the y absolute coordinate in a screen for start dragging

 

dropX

the x absolute coordinate in a screen to drop

 

dropY

the y absolute coordinate in a screen to drop

 

button

possible values

LEFT_MOUSE_BUTTON = 0

MIDDLE_MOUSE_BUTTON = 1

RIGHT_MOUSE_BUTTON = 2

clip_image011

 

None

clip_image015

 

clip_image001        you can use also a combination of MouseDown, MouseMove and MouseUp methods

MouseClick Method

clip_image005

Method performs a single click ( left or right ) on a specific location in the screen

clip_image007

object.MouseClick( x, y, Button )

clip_image009

Parameter

Description

object

Always a Mercury.DeviceReplay object

x

the x absolute coordinate in a screen for perform the click

y

the y absolute coordinate in a screen for perform the click

button

possible values

LEFT_MOUSE_BUTTON = 0

MIDDLE_MOUSE_BUTTON = 1

RIGHT_MOUSE_BUTTON = 2

clip_image011

None

clip_image013

The following example requires a preparation. the purpose of the example is to execute a DragAndDrop method on www.advancedqtp.com site. if you record the drag and drop action… nothing will be recorded. so this is an example how to support some kind of actions. this example was tested on IE.

open your IE Browser and navigate to  www.advancedqtp.com. The example will swap dbx-handle items. those objects can be dragged to customize the display.

clip_image017

Open QTP ( with web add-in ), Open a new test, open the object repository and add The Browser and Page to the local object repository.

clip_image019

Rename the objects…

clip_image021

Option Explicit

Const LEFT_MOUSE_BUTTON = 0

 

Dim oWebElemDesc1, oWebElemDesc2

Dim oWebElem1, oWebElem2

Dim devRep

Dim nX1, nX2, nY1, nY2, nH1, nH2, hwnd

Dim point1, point2

 

' ** This class holds a point coordinate

Class Point

   Private mX, mY

   Property Let X( ByVal value )

      mX = value

   End Property

   Property Get X()

      X  = mX

   End Property 

   Property Let Y( ByVal value )

      mY = value

   End Property

   Property Get Y()

      Y  = mY

   End Property    

End Class

 

' ** Retrieving the handle of the browser

hwnd = Browser("QTP").GetROProperty( "hwnd" )

Window( "hwnd:=" & hwnd ).Activate

' ** Create a description for 'Program Professionally’

Set oWebElemDesc1 = Description.Create()

oWebElemDesc1( "micclass" ).Value = "WebElement"

oWebElemDesc1( "html tag" ).Value = "H3″

oWebElemDesc1( "innertext" ).Value = "Program Professionally"

oWebElemDesc1( "class" ).Value = "dbx-handle dbx-handle-cursor"

' ** Create a description for 'Links’

Set oWebElementDesc2 = Description.Create()

oWebElemDesc2( "micclass" ).Value = "WebElement"

oWebElemDesc2( "html tag" ).Value = "H3″

oWebElemDesc2( "innertext" ).Value = "Links"

oWebElemDesc2( "class" ).Value = "dbx-handle dbx-handle-cursor"

' ** Searching for the elements

With Browser( "QTP" ).Page( "QTP" )

   If .ChildObjects( oWebElemDesc1 ).Count = 1 Then

      Set oWebElem1 = .WebElement( oWebElemDesc1 )

      If .ChildObjects( oWebElemDesc2 ).Count = 1 Then

         Set oWebElem2 = .WebElement( oWebElemDesc2 )

      Else

         Print "Web Element 'Program Professionally’ was not found."

         ExitTest( micFail )

      End If

   Else

      Print "Web Element 'Program Professionally’ was not found."

      ExitTest( micFail )

   End If

End With

' ** Retrieve elements dimensions

nX1 = oWebElem1.GetROProperty( "abs_x" )

nH1 = oWebElem1.GetROProperty( "height" )

nY1 = oWebElem1.GetROProperty( "abs_y" )

nX2 = oWebElem2.GetROProperty( "abs_x" )

nH2 = oWebElem2.GetROProperty( "height" )

nY2 = oWebElem2.GetROProperty( "abs_y" )

Set point1 = New Point

point1.X = nX1 + 10

point1.Y = nY1 + nH1 - 10

Set point2 = New Point

' ** Dragging up

If nY1 > nY2 Then

   point2.X = nX2 + 20

   point2.Y = nY2 + nH2 - 20

Else

   ' ** Dragging down

   point2.X = nX2 + 20

   point2.Y = nY2 + nH2 + 20

End If

Set devRep = CreateObject( "Mercury.DeviceReplay" )

devRep.DragAndDrop point1.X, point1.Y, _

       point2.X, point2.Y, LEFT_MOUSE_BUTTON

MouseDblClick Method

clip_image005

 

Method performs a double click ( left or right ) on a specific location in the screen

clip_image007

 

object.MouseDblClick( x, y, Button )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

x

the x absolute coordinate in a screen for perform the double-click

 

y

the y absolute coordinate in a screen for perform the double-click

 

button

possible values

LEFT_MOUSE_BUTTON = 0

MIDDLE_MOUSE_BUTTON = 1

RIGHT_MOUSE_BUTTON = 2

clip_image011

 

None

MouseDown Method

clip_image005

 

Method performs a click ( left or right ) on a specific location in the screen, but leaves the mouse clicked.

clip_image007

 

object.MouseDown( x, y, Button )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

x

the x absolute coordinate in a screen for perform the click

 

y

the y absolute coordinate in a screen for perform the click

 

button

possible values

LEFT_MOUSE_BUTTON = 0

MIDDLE_MOUSE_BUTTON = 1

RIGHT_MOUSE_BUTTON = 2

clip_image011

 

None

clip_image015

 

clip_image001        Use always MouseUp Method after the MouseDown.

MouseUp Method

clip_image005

 

Method release a previous MouseDown Method

clip_image007

 

object.MouseDown( x, y, Button )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

x

the x absolute coordinate in a screen for perform the mouse release

 

y

the y absolute coordinate in a screen for perform the mouse release

 

button

possible values

LEFT_MOUSE_BUTTON = 0

MIDDLE_MOUSE_BUTTON = 1

RIGHT_MOUSE_BUTTON = 2

clip_image011

 

None

clip_image015

 

clip_image001        Use always MouseUp Method after the MouseDown.

MouseMove Method

clip_image005

 

Method release a previous MouseDown Method

clip_image007

 

object.MouseDown( x, y )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

x

the x absolute coordinate in a screento mve the mouse to.

 

y

the y absolute coordinate in a screento mve the mouse to.

clip_image011

 

None

clip_image015

 

clip_image001        Debug your scripts when retrieving coordinated in run time.

clip_image001        Move the mouse to a specific location to set the focus on an item, or before executing a keyboard action.

SetSynchronizationTimeout Method

clip_image005

 

Set a new synchronization timeout

clip_image007

 

object.MouseDown( x, y )

clip_image009

 

Parameter

Description

 

object

Always a Mercury.DeviceReplay object

 

nSyncTimeout

the synchronization timeout

 

is_sec

Boolean value that indicates the nSyncTimeout is in seconds

clip_image011

 

None

clip_image015

 

clip_image001        Not recommended to modify the value.

Key Codes Reference

clip_image023

Figure 1 - United States Dvorak

Const

#

Description

VK_ESCAPE

1

Primarily used to cancel a command (instead of pressing Enter) or to escape from a process which may be in an odd state.

VK_1

2

clip_image025        Numeric Key 1. combined with VK_SHIFT will display
        an exclamation mark depend on your keyboard layout 

VK_2

3

clip_image027        Numeric Key 1. combined with VK_SHIFT will display
        an at sign depend on your keyboard layout

VK_3

4

clip_image029        Numeric Key 3. combined with VK_SHIFT will display
        a number sign depend on your keyboard layout

VK_4

5

clip_image031        Numeric Key 4. combined with VK_SHIFT will display
        a dollar sign depend on your keyboard layout

VK_5

6

clip_image033        Numeric Key 5. combined with VK_SHIFT will display
        a percent sign depend on your keyboard layout

VK_6

7

clip_image035        Numeric Key 6. combined with VK_SHIFT will display
        a caret sign depend on your keyboard layout

VK_7

8

clip_image037        Numeric Key 7. combined with VK_SHIFT will display
        an ampersand sign depend on your keyboard layout

 

VK_8

9

clip_image039        Numeric Key 8. combined with VK_SHIFT will display
        an asterik sign depend on your keyboard layout

VK_9

10

clip_image041        Numeric Key 9. combined with VK_SHIFT will display
        an open round bracket sign depend on your keyboard layout

VK_0

11

clip_image043        Numeric Key 0. combined with VK_SHIFT will display
        a close round bracket sign depend on your keyboard layout

VK_MINUS

12

clip_image045        Minus Key ( - )  and underscore ( _ ) with VK_SHIFT.   
        depends on your keyboard layout.

VK_EQUAL

13

clip_image047         Equal Key ( = ) Or Plus key ( + ) with VK_SHIFT.   
         Depends on your keyboard layout.

VK_BACKSPACE

14

clip_image049             Used to delete one character at a time to the left
             of the cursor. You can also click and drag to highlight text and then press the Backspace key to delete text.

VK_TAB

15

clip_image051           Used to set tab positions in a document. Setting
           tab positions allows you to move the cursor to defined positions, for instance when typing figures in columns. Used in conjunction with the Shift key you can jump to the previous tab position.

VK_Q

16

clip_image053       Capital Q combined with Shift or CAPS-LOCK pressed

 

VK_W

17

clip_image055       Capital W combined with Shift or CAPS-LOCK pressed

 

VK_E

18

clip_image057       Capital E combined with Shift or CAPS-LOCK pressed

 

VK_R

19

clip_image059       Capital R combined with Shift or CAPS-LOCK pressed

 

VK_TAB

20

Used to set tab positions in a document. Setting tab positions allows you to move the cursor to defined positions, for instance when typing figures in columns. Used in conjunction with the Shift key you can jump to the previous tab position.

VK_Y

21

clip_image061       Capital Y combined with Shift or CAPS-LOCK pressed

 

VK_U

22

clip_image063       Capital U combined with Shift or CAPS-LOCK pressed

 

VK_I

23

clip_image065        Capital I combined with Shift or CAPS-LOCK pressed

 

VK_O

24

clip_image067       Capital O combined with Shift or CAPS-LOCK pressed

VK_P

25

clip_image069       Capital P combined with Shift or CAPS-LOCK pressed

 

VK_OBRACKET

26

clip_image071        Open Square bracket key ( [ ) or Open qurly bracket  
        key (
{ ) with VK_SHIFT. depend on your keyboard layout

VK_CBRACKET

27

clip_image073         Close Square bracket ( ] ) or Close qurly bracket key
         (
} ) with VK_SHIFT. depend on your keyboard layout

VK_RETURN

28

clip_image075              This key is used to send the cursor to the
              beginning of the next line (for instance when typing text in a word processing package). It is also used to finish a command and tell the computer to execute the command just typed. There are usually two of these keys.

VK_CONTROL

29

clip_image077           Cannot be used on its own. Used in conjunction with
           other keys to carry out a specific function eg Ctrl/Alt/Del performs a system restart. There are usually two of these keys.

VK_A

30

clip_image079        Capital A combined with Shift or CAPS-LOCK pressed

 

VK_S

31

clip_image081        Capital S combined with Shift or CAPS-LOCK pressed

 

VK_D

32

clip_image083        Capital D combined with Shift or CAPS-LOCK pressed

 

VK_F

33

clip_image085        Capital F combined with Shift or CAPS-LOCK pressed

VK_G

34

clip_image087        Capital G combined with Shift or CAPS-LOCK pressed

VK_H

35

clip_image089        Capital H combined with Shift or CAPS-LOCK pressed

VK_J

36

clip_image091        Capital H combined with Shift or CAPS-LOCK pressed

VK_K

37

clip_image093        Capital K combined with Shift or CAPS-LOCK pressed
z

VK_L

38

clip_image095         Capital L combined with Shift or CAPS-LOCK pressed

 

VK_SEMICOLON

39

clip_image097       Semicolon sign ( ; ) or Colon sign ( : ) with
       VK_SHIFT. depend on your keyboard layout

VK_SINGLE_QUOTE

40

clip_image099        Single Quote sign ( ' ) or double quote sign ( " ) with
        VK_SHIFT.
depend on your keyboard layout

VK_APOSTROPHE

41

clip_image101        apostrophe sign ( ` ) or tiled sign ( ~ ) with 
        VK_SHIFT.
depend on your keyboard

VK_SHIFT

42

clip_image103               Changes lower case letters to upper case, and
               numbers to symbols. There are usually two of
  these keys.

VB_PIPE

43

clip_image105        Backslash sign ( \ ) or pipe sign ( | ) with VK_SHIFT.  
        depend on your keyboard layout.

VK_Z

44

clip_image107        Capital Z combined with Shift or CAPS-LOCK pressed

VK_X

45

clip_image109        Capital X combined with Shift or CAPS-LOCK pressed

VK_C

46

clip_image111        Capital C combined with Shift or CAPS-LOCK pressed

VK_V

47

clip_image113        Capital V combined with Shift or CAPS-LOCK pressed

VK_B

48

clip_image115        Capital B combined with Shift or CAPS-LOCK pressed
 

VK_N

49

clip_image117        Capital B combined with Shift or CAPS-LOCK pressed

VK_M

50

clip_image119        Capital M combined with Shift or CAPS-LOCK pressed

VK_COMMA

51

clip_image121        Comma sign ( , ) Or Left chevron ( < ). depend on
        your keyboard layout.

VK_DOT

52

clip_image123        Dot sign ( . ) or Right chevron sign ( > ). depend on
        your keyboard layout.

VK_SLASH

53

clip_image125        Slash sign ( / ) or question mark ( ? ) with
        VK_SHIFT. depend on your keyboard layout.

VK_RSHIFT

54

clip_image103                Changes lower case letters to upper case, and
                numbers to symbols.

VK_MULTIPLY

55

Multiple sign ( * )

VK_MENU

56

clip_image128          Used in conjunction with other keys to enter
          keywords. Also used to enter ASCII codes by holding
down the Alt key and entering the number from the numeric keypad.

VK_SPACE

57

Space Key

VK_CAPITAL

58

clip_image130            CAPS LOCK key

VK_F1

59

As a throwback to DOS days, you will find that the F1 key will often bring up a help menu. If you press F1 while working in a program, help for that program will usually appear. If you press F1 while at the Windows desktop or when the Windows Explorer is open, a Windows help screen will pop up. If you happen to be working in a program and would like to see the Windows help screen, simply press the Windows key (the key with the Windows logo on the bottom row of keys) on your keyboard and press F1 at the same time.

VK_F2

60

You can use the F2 key to rename an item when working in Windows. Highlight any folder or file, and press F2. You will then be able to type a new name for the object. After you type the new name, just click outside the name box or press the enter key to make the name change. This works just like right-clicking a file or folder and selecting Rename.

VK_F3

61

When you are working in Windows, the F3 key will open the Find Files window.

VK_F4

62

The F4 key has some very useful functionality. You can press F4 to open the Address bar when working in Internet Explorer. This will allow you to type the address of a Web page for quick access.

You can also press the Alt key and the F4 key at the same time to close the open Window that you are currently working on

VK_F5

63

The F5 key is the refresh key. You can press F5 when viewing a Web page to make sure that you have the most current version of that Web page. You can also use F5 when in Windows to refresh the screen. This can be a handy shortcut. If perhaps you are viewing the contents of a floppy disk and you insert a new floppy, your screen will still show the contents of the first floppy. Just press F5 to refresh the screen and see the contents of the floppy you just inserted.

VK_F6

64

This key is often used to move the cursor around the structure of the program. Pressing it will often cycle you from window to window.

VK_F7

65

The F7 key does not have any functionality in Windows. It may, however be used in some individual programs. To find out if it is available in the program you are using, bring up the program’s help screen and type in the words function key.

VK_F8

66

The F8 key can be used to access Safe Mode if pressed during the computer’s boot up process. This is a trouble-shooting mode which will start the computer with minimal drivers.

VK_F9

67

The F9 key does not have any functionality in Windows. It may, however be used in some individual programs. To find out if it is available in the program you are using, bring up the program’s help screen and type in the words function key.

VK_F10

68

F10 is the key that is used to activate the menu bar in many programs. You can use F10 to highlight the first menu choice, and then use the arrow keys to move around the menus. Pressing the Shift key while pressing F10 will bring up the shortcut menu. This is similar to right-clicking on an object.

VK_NUMLOCK

69

Allows the numeric keys to be used on the numeric keypad, rather than the cursor control keys. NumLock mode is activated by pressing the key once and is indicated by a light on the panel above the numeric keypad. Press the key again to return to normal mode.

VK_SCROLL

70

Can control the way the cursor control keys operate in some programs. Many applications ignore this setting. ScrollLock mode is activated by pressing the key once and is indicated by a light on the panel above the numeric keypad. Press the key again to return to normal mode.

VK_HOME

71

Moves your cursor to the beginning of the current line of typed characters.

VK_NUMPAD7

71

Only when VK_NUMLOCK is pressed.

VK_UP

72

Up arrow key

VK_NUMPAD8

72

Only when VK_NUMLOCK is pressed.

VK_PRIOR

73

Moves your cursor up one page of information.

VK_NUMPAD9

73

Only when VK_NUMLOCK is pressed.

VK_SUBTRACT

74

Subtract Key. ( - )

VK_LEFT

75

Left Arrow key

VK_NUMPAD4

75

Only when VK_NUMLOCK is pressed.

VK_CLEAR

76

 

VK_NUMPAD5

76

Only when VK_NUMLOCK is pressed.

VK_RIGHT

77

Right Arrow key

VK_NUMPAD6

77

Only when VK_NUMLOCK is pressed.

VK_ADD

78

Plus sign

VK_END

79

Moves your cursor to the end of the current line of typed characters.

VK_NUMPAD1

79

Only when VK_NUMLOCK is pressed.

VK_DOWN

80

Down arroy key.

VK_NUMPAD2

80

Only when VK_NUMLOCK is pressed.

VK_NEXT

81

Moves your cursor down one page of information.

VK_NUMPAD3

81

Only when VK_NUMLOCK is pressed.

VK_INSERT

82

Inserts characters in a line of text. The remaining text moves one cursor position to the right for each character inserted.

VK_NUMPAD0

82

Only when VK_NUMLOCK is pressed.

VK_DELETE

83

Deletes the character to the right of the cursor position. The remaining text moves one cursor position to the left, for each character deleted. You can also click and drag to highlight text and then press the Delete key to delete text.

VK_SNAPSHOT

84

Prints everything displayed on the screen to an attached printer.

VK_BACKSLASH

86

Backslash sign ( \ )

VK_F11

87

Press F11 when you are working in Internet Explorer and the window will open to full screen mode. This will make all the toolbars disappear and can be useful to see more information on the screen.  Press F11 when you are in full screen mode will toggle you back to your normal view.

VK_F12

88

The F12 key does not have any functionality in Windows. It may, however be used in some individual programs. To find out if it is available in the program you are using, bring up the program’s help screen and type in the words function key.

VK_NUMPAD5

89

 

VK_ZOOM

98

 

VK_HELP

99

 

VK_F13

100

 

VK_F14

101

 

VK_F15

102

 

VK_F16

103

 

VK_F17

104

 

VK_F18

105

 

VK_F19

106

 

VK_F20

107

 

VK_F21

108

 

VK_F22

109

 

VK_F23

110

 

Posted in QTP Techniques

7 Responses to “The Undocumented DeviceReplay”

  1. manjunath Says:

    [-]

    this doc is really very helpful,

    thanx lot….

  2. gilidar Says:

    [-]

    how can i preform a keybourd click on Print scrn and then paste the buffer to jpg

  3. The Undocumented DeviceReplay (Translated to Russian) | AdvancedQTP Says:

    [-]

    […] the key numeric code for more information on key codes see Key Codes Reference […]

  4. baluqa Says:

    [-]

    This doc is very nice to have better understanding of QTP in DOS

  5. jillcireland Says:

    [+]

    Fantastically helpful, but I'm having trouble getting this to work when the Windows desktop is extended onto multiple monitors - s... ...

  6. The Undocumented DeviceReplay | Torkan Blog Says:

    [-]

    […] http://www.advancedqtp.com/knowledge-base/articles/qtp-tricks4/the-undocumented-devicereplay/ […]

  7. Allwyn Says:

    [+]

    Hi Im getting "Object Not visible " Error whenever i try hwnd = Browser( "B" ).GetROProperty( "hwnd" ) Window( "hwnd:=" &... ...

Leave a Reply

You must be logged in to post a comment.

This article was viewed 3314 times