vbscriptautomated-testsqtpwsh

How do I use WScript.Shell SendKeys to send Number Pad key strokes?


I am trying to use WScript.Shell SendKeys method to emulate sending a key press from the Number Pad.

I have an application that I am writing automated testing for using QTP. It is a Web Browser based application and the input is into a Java App within the web page. The input only accepts key presses from the Number Pad and the Enter key.

So far I am using this code:

Dim strInputKey
strInputKey = "{ENTER}"
Set objWsh = CreateObject("WScript.Shell")
Browser("Launch Browser").Page("Test Application").WebElement("Item ID").Click
objWsh.SendKeys strInputKey

This works fine for sending the Enter key, but I can't quite figure out if there is a way to send Number Keys. Any help would be greatly appreciated.

I am not sure if there are any undocumented ways of achieving this. I have read http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx but it doesn't go into great detail.


Solution

  • You'll need to use the keycodes for the number pad.

    Here's a list of them: http://www.empirisoft.com/directrt/help/_helpcontents.htm?directrt_key_codes.htm

    So to send "123", you would need to do:

    objWsh.SendKeys chr(79) & chr(80) & chr(81)