SendKeys is a method used to perform keystroke events on any opened application. Some times QTP may not identify specific objects and Sendkeys can be used in those situations to perform those operations if that can be done with Key strokes. SendKeys is the method of "WScript.Shell" class.
Here is the example of Sending key value "A" to
the application
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "{A}"
Set WshShell = Nothing
We can also use Sendkeys for the operations that involves multiple keystrokes. Say for Instance, If we want our script to close any opened window (using ALT+F4 or ALT+F and X), we can use the below script.
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "%f"
wait 3
WshShell.SendKeys "x"
wait 3
Set WshShell = Nothing
++++++++++++++++++++++++++++++
OR
++++++++++++++++++++++++++++++
WshShell.SendKeys "%f"
wait 3
WshShell.SendKeys "x"
wait 3
Set WshShell = Nothing
++++++++++++++++++++++++++++++
OR
++++++++++++++++++++++++++++++
Set WshShell = CreateObject("WScript.Shell")
wait 2WshShell.SendKeys "%{F4}"
wait 3
Set WshShell = Nothing
Here % is the symbol to send ALT key. For the shift key it
is "+" and for the CTRL key it is "^".
In following table you will find all keys and their argument that you may need.
Name of Key
|
Argument
|
BACKSPACE
|
{BACKSPACE}, {BS}, or {BKSP}
|
BREAK
|
{BREAK}
|
CAPS LOCK {CAPSLOCK}
|
{CAPSLOCK}
|
DEL or DELETE
|
{DEL}
|
DOWN ARROW
|
{DOWN}
|
END
|
{END}
|
ENTER
|
{ENTER} or ~
|
ESC
|
{ESC}
|
HELP
|
{HELP}
|
HOME
|
{HOME}
|
INS or INSERT
|
{INSERT} or {INS}
|
LEFT ARROW
|
{LEFT}
|
NUM LOCK
|
{NUMLOCK}
|
PAGE DOWN
|
{PGDN}
|
PAGE UP
|
{PGUP}
|
PRINT SCREEN
|
{PRTSC}
|
RIGHT ARROW
|
{RIGHT}
|
SCROLL LOCK
|
{SCROLLLOCK}
|
TAB
|
{TAB}
|
UP ARROW
|
{UP}
|
Y 10 times
|
{Y 10}
|
Space
|
" "
|
plus sign
|
"+"
|
caret
|
"^"
|
percent sign
|
"%"
|
tilde
|
"~"
|
No comments:
Post a Comment