There are occasions when keyboard inputs are not recorded or replayed successfully using the normal recording methods of UFT One (QTP). Also many applications depend on keyboard events to trigger the opening of a window/pop-up window or displaying an edit field. To send keyboard inputs to an application using QTP we have many ways. I suggest using them in the order in which they appear below. (I prefer using low-level recording or analog recording recording as the last option in QTP.

Sendkeys Method

1. Use the simplest .Type ( key ) to send keyboard input.

Eg:

Window("Notepad").WinEditor("Edit").Type micF5

2. Use the Windows Scripting SendKeys method

There are some Web/Windows objects which will perform actions when certain key commands, such as CTRL+SHIFT+ESC are entered. These Web/Windows objects do not have a type method associated with them that can be used to replay these keys. In these cases you can use SendKeys method to send keyboard input to your application.
Download and install the Windows Scripting Host.
1. Create a WScript.Shell object.
2. Activate the browser in which you want to execute the keys.
3. Use the SendKeys method to type the key combination.
Example:

'This code executes the CTRL+F key combination (search) on a browser.
Set WshShell = CreateObject("WScript.Shell")

'Activate the browser window
WshShell.AppActivate "Put the label of the browser" 
wait(3)

'The caret (^) represents the CTRL key.
WshShell.SendKeys "^f" 
wait(2)

The SendKeys method will send keystroke(s) to the active window. To send a single character (for example, x), use “x” as the string argument. To send multiple characters (for example, abc), use “abc” as the string argument. You can also send special characters such as SHIFT, CTRL, and ALT, which are represented by the plus sign (+), the caret (^), and the percent sign (%), respectively.
For more information on the SendKeys method, please refer to the MSDN SendKeys Method page.

3. Use Analog or low-level recording when entering keyboard input

4. Use Mercury Device Replay feature

The Device Replay feature is used to perform mouse and keyboard actions against screen co-ordinates that are provided. The Device Replay functions are not automatically recorded, but must be programmed manually in the Editor/Expert View.

1.    Creating the Device Replay Object.
2.    Calling the Device Replay function.
3.    Destroying Device Replay object.

Here is an example to simulate F5 function key using DeviceReplay.

Set obj = CreateObject("Mercury.DeviceReplay")
Window("Notepad").Activate
obj.PressKey 63

The PressKey method uses the appropriate IBM Scan Code value for the key. “63” is the IBM Scan Code value for F5.
For more information on IBM Scan Codes, refer to Lookup Tables.  Click the “Scan Codes & EBCDIC” tab. The value needed for the PressKey method is the decimal value.