• Welcome to Jose's Read Only Forum 2023.
 

IWshShell2.SendKeys Method

Started by José Roca, July 14, 2008, 07:08:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca




The following code runs the Windows calculator and sends it keystrokes to execute a simple calculation.

JScript


var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run("calc");
WScript.Sleep(100);
WshShell.AppActivate("Calculator");
WScript.Sleep(100);
WshShell.SendKeys ("1{+}");
WScript.Sleep(500);
WshShell.SendKeys("2");
WScript.Sleep(500);
WshShell.SendKeys("~");
WScript.Sleep(500);
WshShell.SendKeys("*3");
WScript.Sleep(500);
WshShell.SendKeys("~");
WScript.Sleep(2500);


VBScript


set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WScript.Sleep 100
WshShell.AppActivate "Calculator"
WScript.Sleep 100
WshShell.SendKeys "1{+}"
WScript.Sleep 500
WshShell.SendKeys "2"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 500
WshShell.SendKeys "*3"
WScript.Sleep 500
WshShell.SendKeys "~"
WScript.Sleep 2500


PowerBASIC


DIM pWsh3 AS IWshShell2
DIM lExitCode AS LONG
pWsh2 = NEWCOM "WScript.Shell"
IF ISNOTHING(pWsh2) THEN EXIT FUNCTION
lExitCode = pWsh2.Run(UCODE$("calc"))
SLEEP 100
pWsh2.SendKeys UCODE$("1{+}")
SLEEP 500
pWsh2.SendKeys UCODE$("2")
SLEEP 500
pWsh2.SendKeys UCODE$("~")
SLEEP 500
pWsh2.SendKeys UCODE$("*3")
SLEEP 500
pWsh2.SendKeys UCODE$("~")
SLEEP 2500