Automation Testing, Manual Testing, QTP/UFT 11 , QC/ALM 11 ,SAP TAO, Unix, Selenium, Oracle SQL, Shell Scripting and For Online Trinings to contact me : Cell:+91-8897972059 , Email Id : quicktestprotech@gmail.com

Tuesday, July 26, 2011

QTP Secret Code Chart Revealed For DeviceReplay PressKey, KeyDown, KeyUp and PressNKeys

QTP Secret Code Chart Revealed For DeviceReplay PressKey, KeyDown, KeyUp and PressNKeys



Why this post?
Let’s face it. If you’ve been doing test automation for any length of time you’ve faced situations in which you need to perform mouse or keyboard actions using screen coordinates.
When the Set and Type Methods Suck:
Even though most objects have Set and Type methods, these methods -- for whatever reason -- may not work in all situations. If they don’t then your next step may be to try VBSCript’s sendkey method. But even sendkeys sometimes do not have a way to perform certain actions, such as pressing the left alt key. Hence the need for QTP’s undocumented Device Replay features.
No ASCII No Problem:
A few months back, I posted an article outlining three different ways to use keyboard input in QTP. I recently came across some more Device Replay Key codes for the PressKey, Keydown, Keyup and PressNKeys that I’d like to share with you. These methods are particularly helpful in certain situations in which you need to perform an action using a code that does not have an ASCII equivalent.
Chart of the keyboard key codes for the PressKey, Keydown, Keyup and PressNKeys:
The number keys:
KeystrokeCode to use
11
22
33
44
55
66
77
88
99
00
The keypad number keys:
KeystrokeCode to use
179
280
381
475
576
677
771
872
973
082
The Function keys:
KeystrokeCode to use
F159
F260
F361
F462
F563
F664
F765
F866
F967
F1068
F1187
F1288
The Letter keys:
KeystrokeCode to use
A30
B48
C46
D32
E18
F33
G34
H35
I23
J36
K37
L38
M50
N49
O24
P25
Q16
R19
S31
T20
U22
V47
W17
X45
Y21
Z44
The Enter,Space,Shift,Ctrl and Alt keys:
KeystrokeCode to use
ENTER28
SPACE57
LEFT SHIFT42
LEFT CTRL29
LEFT ALT56
RIGHT SHIFT54
RIGHT CTRL157
RIGHT ALT184
;39
'40
,51
.52
/53
The Weird/Other keys:
KeystrokeCode to use
-12
[26
]27
`41
=13
BACKSPACE14
CAPSLOCK58
DELETE211
DOWN208
END207
HOME199
INSERT210
LEFT203
NUMLOCK69
KEYPAD DECIMAL83
KEYPAD DIVIDE181
KEYPAD ENTER156
KEYPAD MINUS74
KEYPAD MULTIPLY55
PAUSE116
PAGE DOWN209
PAGE UP201
RIGHT205
SCROLL LOCK70
TAB15
UP20O
Examples:
'Device Replay Example using the calculator with the multiple key
Set myReplay = Createobject("Mercury.DeviceReplay")
SystemUtil.Run "calc.exe"
Window("regexpwndtitle:=Calculator").Activate
myReplay.PressKey 73'9
wait 1
myReplay.PressKey 55' Keypad Multiply
wait 1
myReplay.PressKey 81'3
wait 1
myReplay.PressKey 156'Enter
The end result should be 27
'Device Replay Example using notepad with the shift key
Set myReplay = Createobject("Mercury.DeviceReplay")
SystemUtil.Run "notepad.exe"
wait 1
Window("nativeclass:=Notepad").Activate
wait 1
myReplay.KeyDown 42''Hold shift key down
wait 1
myReplay.PressKey 36'T
wait 1
myReplay.PressKey 24'H
wait 1
myReplay.PressKey 18'I
wait 2
myReplay.KeyUp 42'Press shift key up
wait 1
myReplay.PressKey 57 'space
wait 1
myReplay.PressKey 36' t
wait 1
myReplay.PressKey 24 'h
wait 1
myReplay.PressKey 18 ie
The example should type out: THIthi

1 comment:

  1. If you are going to repost someone else's original content, please credit the original poster. I'm sure Joe would appreciate it. I'm glad your link under the "No ASCII..." section still points to his site, at least.

    https://www.joecolantonio.com/2011/07/19/qtp-secret-code-chart-revealed-for-devicereplay-presskey-keydown-keyup-and-pressnkeys/

    ReplyDelete

Loading...