Automation Testing

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

By Test Guild
  • Share:
Join the Guild for FREE

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:

Keystroke Code to use
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9

The keypad number keys:

Keystroke Code to use
1 79
2 80
3 81
4 75
5 76
6 77
7 71
8 72
9 73
0 82

The Function keys:

Keystroke Code to use
F1 59
F2 60
F3 61
F4 62
F5 63
F6 64
F7 65
F8 66
F9 67
F10 68
F11 87
F12 88

The Letter keys:

Keystroke Code to use
A 30
B 48
C 46
D 32
E 18
F 33
G 34
H 35
I 23
J 36
K 37
L 38
M 50
N 49
O 24
P 25
Q 16
R 19
S 31
T 20
U 22
V 47
W 17
X 45
Y 21
Z 44

The Enter, Space, Shift, Ctrl and Alt keys:

Keystroke Code to use
ENTER 28
SPACE 57
LEFT SHIFT 42
LEFT CTRL 29
LEFT ALT 56
RIGHT SHIFT 54
RIGHT CTRL 157
RIGHT ALT 184
; 39
40
, 51
. 52
/ 53

The Weird/Other keys:

Keystroke Code to use
12
[ 26
] 27
` 41
= 13
BACKSPACE 14
CAPSLOCK 58
DELETE 211
DOWN 208
END 207
HOME 199
INSERT 210
LEFT 203
NUMLOCK 69
KEYPAD DECIMAL 83
KEYPAD DIVIDE 181
KEYPAD ENTER 156
KEYPAD MINUS 74
KEYPAD MULTIPLY 55
PAUSE 116
PAGE DOWN 209
PAGE UP 201
RIGHT 205
SCROLL LOCK 70
TAB 15
UP 20O
A bearded man with blue glasses and a black-and-white jacket smiles at a microphone in a studio setting.

About Joe Colantonio

Joe Colantonio is the founder of TestGuild, an industry-leading platform for automation testing and software testing tools. With over 25 years of hands-on experience, he has worked with top enterprise companies, helped develop early test automation tools and frameworks, and runs the largest online automation testing conference, Automation Guild.

Joe is also the author of Automation Awesomeness: 260 Actionable Affirmations To Improve Your QA & Automation Testing Skills and the host of the TestGuild podcast, which he has released weekly since 2014, making it the longest-running podcast dedicated to automation testing. Over the years, he has interviewed top thought leaders in DevOps, AI-driven test automation, and software quality, shaping the conversation in the industry.

With a reach of over 400,000 across his YouTube channel, LinkedIn, email list, and other social channels, Joe’s insights impact thousands of testers and engineers worldwide.

He has worked with some of the top companies in software testing and automation, including Tricentis, Keysight, Applitools, and BrowserStack, as sponsors and partners, helping them connect with the right audience in the automation testing space.

Follow him on LinkedIn or check out more at TestGuild.com.

  1. Great post Joe.

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

  2. 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

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

  4. 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.

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

  6. 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

  7. 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!

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

  9. 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.

  10. Hi Joe,

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

  11. 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.

  12. 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?

  13. I am facing trouble in using “Mercury.Clipboard”.

    It throws an error : “Active’x component can’t create object: Mercury.Clipboard”.
    Any help or advice is really appreciated.

  14. Hi Joe, HP or rather Micro Focus UFT is a slow tool which uses the dead language VbScript for web ui automation. I wonder if the tool is still useful for any web ui automation. Would you recommend UFT under for web ui under any circumstances ?

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

5 Top Model Context Protocol Automation Tools (MCP Guide 2025)

Posted on 04/09/2025

What is Model Context Protocol (MCP) Model Context Protocol (MCP) is an open ...

What is TDD (Test Driven Development)

Posted on 04/05/2025

What is Test-Driven Development (TDD)? Test-Driven Development is a software development approach that ...

The Best Open Source API Testing Tools for 2025

Posted on 04/01/2025

Here is my list of the best open source API testing tools for ...