Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send a combination of keys
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi All,

I need to press "Ctrl + Alt + P" at a time to enable an edit box and I wrote the code below but it didn't work.

Code:
Set WShell = CreateObject("WScript.Shell")    
WShell.SendKeys "^%(P)"

I tried even few more combinations but without success.

Can anybody come up with a solution?
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
Hi,

it will work properly

I need to press "Ctrl + Alt + P" at a time to enable an edit box and I wrote the code below but it didn't work.

[quote]Set WShell = CreateObject("WScript.Shell")
WShell.SendKeys "^%p"
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
It did not work either.
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
Just to make sure you know, SendKeys will not work unless the window you want to send the keystrokes to is active (maybe use Window("hwnd:=" & hWnd).Activate or some other method of activating the target window). Same for Mercury.DeviceReplay, but here is the method to do it with that object (VK_MENU is Alt):

More info: Device Replay in QTP/UFT

Code:
Const VK_CONTROL = 29
Const VK_MENU = 56
Const VK_P = 25

Set deviceReplay = CreateObject("Mercury.DeviceReplay")
deviceReplay.KeyDown VK_CONTROL
deviceReplay.KeyDown VK_MENU
deviceReplay.PressKey VK_P
deviceReplay.KeyUp VK_MENU
deviceReplay.KeyUp VK_CONTROL
Reply
#5
Solved: 11 Years, 3 Months, 3 Weeks ago
Thanks man..It works perfect.
Reply
#6
Solved: 11 Years, 3 Months, 3 Weeks ago
This does work REALLY well! Thanks for sharing it. Just curious...is "VK_" just preference or does it have a purpose?
Reply
#7
Solved: 11 Years, 3 Months, 3 Weeks ago
It stands for "Virtual Key." The actual enumerations in .NET are named that way. In VBScript, it's just easier to define the constants in the script than try to figure a way to get the values from the .NET framework.
Reply
#8
Solved: 11 Years, 3 Months, 3 Weeks ago
Ah, thank you for the clarification. I've had to head into QTP without a VB background. I did do some programming (long before VB was created) and have been scripting in Second Life, so the logic behind it all is familiar, but I was unaware of the conventions. Thanks again. Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to press the space bar with send keys method Hari Prasad 5 25,237 06-03-2016, 10:47 AM
Last Post: Vijayaragavan.thangam
  Unable to send an email from Outlook which is already opened as draft attiliv 0 2,239 03-24-2013, 11:14 AM
Last Post: attiliv
  send arguments to qtp hadar 0 1,963 02-04-2013, 10:15 PM
Last Post: hadar
  Send key method does not set value on webEdit object. sandeep arora 1 14,602 04-05-2012, 05:27 PM
Last Post: verma.vik6
  Send Data from MSWord document 2 Excel File kisskasa 0 2,855 01-10-2012, 01:51 PM
Last Post: kisskasa

Forum Jump:


Users browsing this thread: 1 Guest(s)