I've been looking everywhere and have not found a solution for this.
I have written a script to display two alternating webpages forever
(infinite loop). It works great!
However, I want it to run until a key is pressed, eg. ESC or maybe a
keypress "x" or whatever..
There does not seem to be any way to trap/scan for a keypress in VBScript.
There only seems to be InputBox, MsgBox, etc..
I guess I am looking for something like the 'inkey()' function or similar in
Basic/VisualBasic. I am new to VBScripting...
Any ideas how I can achieve this?
The script is below
Many thanks
Jason
Dim IE
On Error Resume Next
set wshShell = WScript.CreateObject ("WSCript.shell")
Set IE = CreateObject ("InternetExplorer.Application")
IE.Visible = 1
IE.TheaterMode = 1
Do While true ' want do while ESC key is not pressed here!!!
IE.Navigate ("C:\temp\file1.htm")
Do While IE.busy
JustChecking = 1
Loop
WScript.Sleep 10000
IE.Navigate ("C:\temp\file2.htm")
Do While IE.busy
JustChecking = 1
Loop
WScript.Sleep 10000
Loop
Since there is no console, there is no facility for a VBS script to do
what you want by itself. However, since you are using IE, its DOM
provides the ability to do this, for example ...
Dim IE, bEsc
On Error Resume Next
Set IE = CreateObject ("InternetExplorer.Application")
IE.Visible = true
IE.TheaterMode = true
bEsc = false
Do While bEsc = False and (err.number = 0)
IE.Navigate "C:\temp\file1.htm"
Do While IE.busy : wsh.sleep 100 : Loop
set IE.document.body.onkeypress = GetRef("Checkit")
for i = 1 to 100
if (err.number <> 0) or bEsc then exit do
WScript.Sleep 100
next
IE.Navigate "C:\temp\file2.htm"
Do While IE.busy : wsh.sleep 100 : Loop
set IE.document.body.onkeypress = GetRef("Checkit")
for i = 1 to 100
if (err.number <> 0) or bEsc then exit do
WScript.Sleep 100
next
Loop
IE.Visible = false
IE.quit
sub Checkit
if IE.document.parentWindow.event.keycode = 27 then bEsc = true
end sub
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
I never would have found that. I have been searching for days...
I need to learn more about what you can do with applications' DOMs.
Great info. thanks again.
Jason
I've been looking for days... Guess I need to learn more about application
DOMs and how to use them.
Many thanks again.
Jason
---------------------------------
On Error Resume Next
'Ctrl
keys(0) = 17
'Alt
keys(1) = 18
'F
keys(2) = 70
sleep_time = 50
Set ws = WScript.CreateObject("WScript.Shell")
Set excel = WScript.CreateObject("Excel.Application")
If Err.Number <> 0 Then
ws.Run """" & Wscript.ScriptFullName & """"
Wscript.Quit
End If
Do While true
For i = 0 To (UBound(keys) - 1)
keystate =
excel.ExecuteExcel4Macro("CALL(""user32"",""GetKeyState"",""JJ""," &
keys(i) & ")")
If(keystate = 0 Or keystate = 1) Then
Exit For
End If
Next
If (i = UBound(keys)) Then
msgbox "got key down!"
End If
Wscript.Sleep sleep_time
Loop
-------------------------------
This is not a universal way for the web application.
But for creating a local script, ExecuteExcel4Macro can be a rocket
dive to take us the world of win32!!