For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
Selenium+Appium+Cucumber 19th March 2018 9.30 AM - 11.00 AM IST 45 Days ClassRoom + Online Mind Q Madhapur
Selenium+Appium+Cucumber 26th March 2018 7.30 AM - 9.30 AM IST 35 Days ClassRoom + Online Mind Q Madhapur

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Friday, March 26, 2010

Click on Object by Holding CTRL Key

We may get some situations to click on a link by holding CTRL Key. The normal click operation is not capable of doing that operation. It can click on the object using Left, Right and Middle Buttons of the mouse. Even the Sendkeys method of WSH cannot hold CTRL key.
The other option is Mercury Device Replay. The hidden object of the QTP. It is providing some methods to press and release a particular key of the key board. The below function will click on an object by holding CTRL key.

Function ClickObjectWithCtrlKey(Object)
'Declare Variables
Dim oDeviceReplay
Dim X_Axis
Dim Y_Axis
'Assign The CTRL key Index number to constant
Const VK_CONTROL = 29
'Check for object Existance
If Object.Exist(5) Then
' Create Device Replay Object
Set oDeviceReplay= CreateObject( "Mercury.DeviceReplay" )
'Press CTRL Key
oDeviceReplay.KeyDown VK_CONTROL
'Get X&Y axes of the object from application
'Click on the object
oDeviceReplay.MouseClick X_Axis,Y_Axis,LEFT_MOUSE_BUTTON
'Release the CTRL Key
oDeviceReplay.KeyUp VK_CONTROL
End If
End Function
'Register the function to Link Class
RegisterUserFunc "Link","ClickObjectWithCtrlKey","ClickObjectWithCtrlKey"
'Call the function
'Unregister the Function
UnregisterUserFunc "Link","ClickObjectWithCtrlKey"

Note: Before executing this function the window/Browser of the object should be the first window of the desktop. This function works good in a continuation run. 
Click here to see the script for activating a opened window/browser.