Interactive PowerBasic Forum

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Scripting => Windows Script Host => Topic started by: José Roca on July 14, 2008, 07:08:43 AM

Title: IWshShell2.SendKeys Method
Post by: José Roca on July 14, 2008, 07:08:43 AM



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