My site uses Google Analytics – which I love – and I’ve been seeing quite a few SendKeys keyword related visits. So this post is a compilation of my blogs most frequently searched for QTP SendKey keywords. To follow along open a new test in QTP and add the following to the top of your script:
set objSetFocus = Window("nativeclass:=Notepad","index:=0")
1. How do I send an enter keystroke using QTP?
You could use the ASCII character for a carriage return Chr(13)
(For more ASCII codes to use in QTP check out :QTP ASCII CHR() CODE CHART )
or use the Tilde character:
Both will emulate an ‘Enter’ key.
2. How do I send a space?
To send a space, send the string ” “
3. How do I to send multiple keystrokes at one time using QTP’s VBscript?
To send multiple keys you can create compound string arguments. For example the following will hold down the Ctrl key, press the H key for the ‘Replace’ and type joe into the Replace window’s find textbox:
4. How do I send a SHIFT, CTRL or Alt keystroke?
The special character for the Shift key in vbscript is the + sign.
For example to hold down the shift key and type a string all in capital letters try this:
The special character for the Ctrl key in vbscript is the ^ sign and the character for the Alt key in vbscript is the % sign
5. How do a send a right mouse click?
Try sending a a shift F10:
6. Are there any Sendkeys best practices?
There are a few I can think of :
- Always move the application to a known start position.
- Always set focus to the object you want to interact with before using SendKeys.
- For synchronization issues use the .exist or wait functionality often in your script.
7. How do I send parenthesis using SendKeys?
Parenthesis are special characters in QTP so one way to do this is to use a combination of the shift key with the numeric nine and zero keys:
8. My SendKeys is not working when I try to send a multiple values.What should I do?
If QTP’s SendKeys is not performing as expected try sending each keystroke a separate line.
9. What is QTPs equivalent for shell?
In QTP you can use the Run Method which can be used to run a file or an application. For example to start notepad:
10. How do a select a checkbox or a row in an object?
If the object like a checkbox has focus sending a blank space should select it:
11. How do I repeat a keystroke multiple times?
This only works for singe keystrokes but if you wanted to type a letter five times you could use this shortcut:
12. What is VBScript’s equivalent for keystroke :
13. What are the QTP VBScript’s string constants for non-visible characters in strings?
|VbCrLf||Chr(13) & Chr(10)||Carriage return and a Linefeed|
|VbNewLine||Chr(13) & Chr(10)||New Line|
14. I don’t see the action I need to perform in the chart above – what should I do?
Try the Device Replay method instead – check out the Device Replay chart (QTP DEVICE REAPLY CODE CHART )
15. I’m using C# not QTP how do I start an application
Use Process() for example:
Process myProcess = new Process():
myProcess.StartInfo.FileName = "cmd";
16. In CSharp what are the SendKeys methods?
Flush() – processes all Window messages in the queue
Send() – this sends keystrokes to an app
SendWait() – Sends keystrokes to an app and waits for the keystrokes to complete.
If you found this helpful you might want to also check out my post 3 ways to use keyboard input in QuickTest Professional: Type, SendKeys and Device Replay.
And as always for my fellow bibliomaniacs who may want to dive deeper into SendKeys , I would also recommend these two books:
1. VBScript Programmer’s Reference. (Sendkey info starts on page 338)
2. A Tester’s Guide to .NET Programming (Expert’s Voice) – This book is for the automation imagineer who may want to create a simple custom GUI sendkeys app (check out page 173 of this book)