Monday, March 16, 2009

Send Keyboard Input to Application

Hi All,

Sending Keyboard Input to an Application :

1st Way:
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

WshShell.Run "calc.exe"
WshShell.AppActivate "Calculator"
WshShell.SendKeys "1{*}"
Wait (3)
WshShell.SendKeys "2"
WshShell.SendKeys "~"
WshShell.SendKeys "*3"
WshShell.SendKeys "~"

2nd way:
For i=1 to datatable.GetRowCount
window("Notepad").WinEditor("Edit").Type datatable("text",1)

3rd Way:
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 Expert View.
Create the Device Replay Object.

Call the desired Device Replay function.

When done with the Device Replay object, release it.


Set ws=createObject("Wscript.Shell")
ws.Run "Notepad.exe"
Set obj = CreateObject("Mercury.DeviceReplay")
Window("Text:=Untitled - Notepad").Activate
obj.PressKey 63

The PressKey method uses the ASCII value for the key.

63 is the ASCII value for F5.
ASCII values for other keys:

F1 - 59

F2 - 60

F3 - 61

F4 - 62

F5 - 63

F6 - 64

F7 - 65

F8 - 66

F9 - 67

F10 - 68

F11 - 87

F12 - 88

No comments:

Post a Comment