I'm using a TEXTAREA element and sending keystrokes to it. It seems to work
fine until a certain point. For example, in the code below, upon loading, it
will loop from 1 to 1000, each time adding a line number then going to the
next line.
Results in the textarea _should_ look like this:
1
2
[...snip...]
999
1000
On my PC, it only goes to about 850 and looks like this:
1
2
[...snip...]
849
850
Occassionally it will stop a few characters more or less, but usually right
about that location.
If I run it through less than 850 (i.e. 800, even 845) it runs just fine.
Maybe it's a machine speed limitation? I'd be curious to know if others get
less or more on faster/slower PCs.
I'm on a 3Ghz Dell Precision with 256MB RAM.
--- Code Below ---
<HTML>
<HEAD>
<TITLE>Default HTA</TITLE>
<HTA:APPLICATION>
</HEAD>
<SCRIPT Language="VBScript">
Sub PutInSampleText()
Set WshShell = CreateObject("WScript.Shell")
textbox.focus
st = timer()
For i = 1 to 1000
WshShell.SendKeys i & "{ENTER}"
Next
End Sub
</SCRIPT>
<BODY onLoad=PutInSampleText>
<TEXTAREA COLS=40 ROWS=30 WRAP="off" ID="textbox"></TEXTAREA>
</BODY>
</HTML>
Perhaps it is a buffer limitation somewhere...
Monkey
Another weird behavior is on refreshing. It will go further but still stall
at a certain point.
Change the top end of the for loop to 2000.
When it loads, it will still run up to 850 or so.
Refresh the HTA (F5 or right-click and refresh) and it will run up to about
1220.
Also it doesn't seem to be timing out based on the loop count, but by the
number of keys it is sending. For example, add a couple spaces or characters
to the SendKeys line:
WshShell.SendKeys i & " {ENTER}"
And it times out even earlier. (Adding 3 spaces it times out on line 566, on
refreshing line 730)
Very odd...
"Monkey" <mnr...@hotmail.com> wrote in message
news:1119311456.3...@g43g2000cwa.googlegroups.com...
<HTML>
<HEAD>
<TITLE>Default HTA</TITLE>
<HTA:APPLICATION>
</HEAD>
<SCRIPT Language="VBScript">
Sub PutInSampleText()
Set WshShell = CreateObject("WScript.Shell")
textbox.focus
j = 0
For i = 1 to 3000
WshShell.SendKeys i & "{ENTER}"
j = j + 1
If j = 100 Then
ccSleep 1
j = 0
End If
Next
End Sub
Sub ccSleep(seconds)
set oShell = CreateObject("Wscript.Shell")
cmd = "%COMSPEC% /c ping -n " & 1 + seconds & " 127.0.0.1>nul"
oShell.Run cmd,0,1
End Sub
</SCRIPT>
<BODY onLoad=PutInSampleText>
<TEXTAREA COLS=40 ROWS=30 ID="textbox"></TEXTAREA>
</BODY>
</HTML>
Michael Reese
[top post]
Good solution. All send-key operations are sensitive to timing and buffer
overruns. The AutoItX Send is more robust, if you can use an ActiveX. It
has different modes to reduce uneeded interpretation or provide more when
needed, includes keys and codes that SendKeys does not, and, significantly,
allows you to set the timing between each send. Slowing down the stream can
often avoid these problems. Your solution is as good as I've seen for
straight WSH operation, though it may have to be customized to different
machines.
Regards,
Joe Earnest
"Monkey" <mnr...@hotmail.com> wrote in message
news:1119851794.5...@g49g2000cwa.googlegroups.com...