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

PerfectoTopAd

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:

00

00

KeystrokeCode to use
11
22
33
44
55
66
77
88
99

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
19 comments
3 ways to use keyboard input in QuickTest Professional: Type, SendKeys and Device Replay — Joe Colantonio -- Test Automation Geek | Bibliomaniac | Software Imagineer - July 21, 2011

[…] This is an undocumented and unsupported QuickTest method, but can be used as a last resort. To employ this method, you’ll need to create a Device Replay object.(Check out the Device Replay Chart of Codes) […]

Reply
Anish Pillai - September 12, 2011

Joe,

Any idea why Device Replay feature is undocumented?

Reply
Abhijeet - May 3, 2012

Great post Joe.

Is there any way to simulate the Windows or the Right Click Key through Device Replay?

Reply
    Joe Colantonio - May 11, 2012

    Abhijeet » Thanks Abhijeet – I think you can mimic a right click by passing the deviceReplay’s Mouse click method the RIGHT_MOUSE_BUTTON option:

    Set deviceReplay = CreateObject(“Mercury.DeviceReplay”)
    deviceReplay.MouseClick getX,getY,RIGHT_MOUSE_BUTTON

    Reply
Louis Vandenberg - May 10, 2013

What is the number code to use for zero (0) on the number keys? (NOT keypad number keys)

Reply
unknown - June 3, 2013

Looks like scancode set 1 to me (MAKE).
Here’s a full list

http://www.computer-engineering.org/ps2keyboard/scancodes1.html

Reply
Tshifhiwa - March 6, 2014

Hi Joe,

Great post, what is the code for an “Esc” key?

Reply
Jim Trout - May 1, 2014

Joe, this has been invaluable. I was a bit thrown by the capital letters when I wanted to use a lower case one, but once I figured out that the numbers refer to the key positions, it was fine.

Reply
mshivnath - September 17, 2014

how to minimize the browser in qtp with the help of send keys and device replay, PressKey, KeyDown, KeyUp and PressNKeys.

Reply
    Joe Colantonio - September 29, 2014

    Hi Does this work to minimize the browser:

    Dim hwnd, isMinimized, isMinimizable

    ‘Find the handle for the Browser window
    hwnd = Browser(“CreationTime:=0”).Object.HWND

    ‘Check if the Browser is already minimized or not
    If Window(“hwnd:=” & hwnd).GetROProperty(“minimized”) = True Then
    isMinimized = True
    Else
    isMinimized = False
    End If

    ‘Check if the Browser is minimizable or not
    If Window(“hwnd:=” & hwnd).GetROProperty(“minimizable”) = True Then
    isMinimizable = True
    Else
    isMinimizable = False
    End If

    ‘Minimize the browser window if it is not already minimized and is minimizable
    If isMinimized = False and isMinimizable = True Then
    Window(“hwnd:=” & hwnd).Minimize
    End If

    Reply
Maze - November 3, 2014

Great document, its been helping me with my coding, However the ASCII code for numbers 1-9 is incorrect, in example the ASCII code for the number 2 is not 2 but 3, enjoy!

Reply
[BLOCKED BY STBV] QTP ASCII CHR() CODE CHART | Joe Colantonio - Test Automation Selenium-UFT-QTP-SoapUI-ALM_LoadRunner and More! - April 3, 2015

[…] What about mouse and keyboard actions? There may be time when you actually need to perform mouse or keyboard actions using screen coordinates. For a step-by-step example on how to do this with QuickTest Professional or Unified Functional Testing check out: QTP Secret Code Chart Revealed For DeviceReplay PressKey, KeyDown, KeyUp and PressNKeys […]

Reply
Sathish Kumar K - April 28, 2016

I need to press “Alt+r” key , currently i’m working in IE browser. Please help with the syntax

Reply
Brian White - July 8, 2016

Joe, you are amazing. Where do you find this stuff? I am just glad you do. Thanks for your continued help. Oh, and I love your API Manifesto book. It is fantastic.

Reply
Naveen - October 24, 2016

Hi Joe,

I want to hold left mouse button for at least 2 or 3 second, may i know how to use it

Reply
    Joe Colantonio - October 25, 2016

    Can you do something like this?
    SwfWindow(“Window”).Type micShiftDwn ‘To press the shift key down
    wait(3)
    SwfWindow(“Window”).Type micShiftUp ‘To release the pressed key.

    Reply
prabhu - January 23, 2017

Device reply is failing 50% of time in remote run. It works fine if I run in local machine. But 50% of cases fails when we run in remote machine.

Any suggestions?

Reply
Click here to add a comment

Leave a comment: