The following example starts the Windows calculator and uses
AppActivate to ensure that the calculator is at the top.
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 IWshShell3
DIM lExitCode AS LONG
DIM vApp AS VARIANT
pWsh3 = NEWCOM "WScript.Shell"
lExitCode = pWsh3.Run(UCODE$("calc"))
SLEEP 100
vApp = "Calculator"
pWsh3.AppActivate vAppSLEEP 100
pWsh3.SendKeys UCODE$("1{+}")
SLEEP 500
pWsh3.SendKeys UCODE$("2")
SLEEP 500
pWsh3.SendKeys UCODE$("~")
SLEEP 500
pWsh3.SendKeys UCODE$("*3")
SLEEP 500
pWsh3.SendKeys UCODE$("~")
SLEEP 2500