What does Mercury Device Replay and Scan Codes have to do with UFT/QTP? In Nov 2007 I wrote an article on 4 Ways to send keyboard input to an application using QTP when it does not record using normal recording The four ways discussed in detail in the article were:

  1. Using Type method
  2. Using SendKeys method
  3. Using Low level/analog recording
  4. Using Mercury.DeviceReplay method

#1 and #2 are used frequently by people however people sparingly use #3 and #4.
They rarely use #3 because it is dependent on mouse coordinates and #4 largely because DeviceReplay remains an undocumented method from Mercury (now HP) even after so many years.

However, we still get questions on this method on QTP/UFT forums and our social media channels like Twitter and Facebook.  Here is a recent tweet

DeviceReplay ScanCodes & UFT/QTP

We can use Mercury.DeviceReplay to send keyboard input on Windows operating system. The challenge arise when we have to find out what value to use for PressKey method.

In this article we will delve into what are the codes or values that can be used for sending keyboard inputs and how they are arrived. Most UFT engineers tend to think that these values are derived from ASCII value. That’s a fallacy. Rather, these values are a decimal equivalent of something known as IBM Scan Codes.

What are Scan Codes?

A scancode (or scan code) is the data that most computer keyboards send to a computer to report which keys have been pressed. A number, or sequence of numbers, is assigned to each key on the keyboard. Source

To understand let us first see the image below.

physical location windows keys

Each key on a standard keyboard is assigned a number as shown in the keyboard layout above. If you have ever noticed, while the positioning for PrtScr/Insert/Pause/Break/PgUp/PgDn/Home/End keys change from keyboard to keyboard , the positioning for function keys, QWERTY keys, numeric keys remain consistent across all modern day laptops and desktops.

All keys on your keyboard are mapped to Scan codes in hexadecimal which are sent to the Windows operating system when we press any key.
PressKey method discussed above use these hexadecimal numbers in decimal format. Here is a complete table mapping Keys on Keyboard, Hexadecimal Scan Code and Decimal Code. You would need Decimal Codes when you need to use PressKey method on Mercury.DeviceReplay object.

KEYScan Code (Hex)Decimal Code ( For UFT)
A1E30
B3048
C2E46
D2032
E1218
F2133
G2234
H2335
I1723
J2436
K2537
L2638
M3250
N3149
O1824
P1925
Q1016
R1319
S1F31
T1420
U1622
V2F47
W1117
X2D45
Y1521
Z2C44
00B11
122
233
344
455
566
677
788
899
90A10
`2941
-0C12
=0D13
\2B43
BKSP0E14
SPACE3957
TAB0F15
CAPS3A58
L SHFT2A42
L CTRL1D29
L ALT3856
R SHFT3654
R CTRLE0,1D157
R ALTE0,38184
ENTER1C28
ESC11
F13B59
F23C60
F33D61
F43E62
F53F63
F64064
F74165
F84266
F94367
F104468
F115787
F125888
PRNT  SCRNE0,2A,  E0,37 
SCROLL4670
PAUSEE1,1D,45, E1,9D,C5
[1A26
INSERTE0,52210
HOMEE0,47199
PG UPE0,49201
DELETEE0,53211
ENDE0,4F207
PG DNE0,51209
U ARROWE0,48200
L ARROWE0,4B203
D ARROWE0,50208
R ARROWE0,4D205
NUM4569
KP /E0,35181
KP *3755
KP -4A74
KP +4E78
KP ENE0,1C156
KP .5383
KP 05282
KP 14F79
KP 25080
KP 35181
KP 44B75
KP 54C76
KP 64D77
KP 74771
KP 84872
KP 94973
]1B27
;2739
'2840
,3351
.3452
/3553

KP stands for KeyPad keys which are available on the right side of all keyboards.

The above table has been derived from this Microsoft document. We have stripped down several terms mentioned in the document to explain the concept for UFT engineers in as much simple terms as possible.

Example: Press F1 using DeviceReplay Method

Set oDevRp = CreateObject ("Mercury.DeviceReplay") oDevRp.PressKey 59 'Press F1

Did this article help you? In case you have any questions, please comment below.