问题
I am currently trying to make an autotyper in VBS and I cannot figure out how to easily input what is to be typed. Right now, this is what my code has to look like:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "notepad"
WScript.sleep 10000
WshShell.SendKeys "H"
WScript.Sleep 100
WshShell.SendKeys "e"
WScript.Sleep 100
WshShell.SendKeys "l"
WScript.Sleep 100
WshShell.SendKeys "l"
WScript.Sleep 100
WshShell.SendKeys "o"
But I really want my code to have all the text that will be auto-typed in just one line instead of me having to repeat the SendKeys
for every letter.
回答1:
I made for you a little example that can type letter by letter as a Typewriter.
Hope this what you are looking for !
strText="Hello ! How are you mate ? Hope that everything is OK !" & vbCrlf &_
"This vbscript is made by Hackoo !"
Call AutoTypeWriter(strText)
'------------------------------------------
Sub AutoTypeWriter(strText)
intPause = 150
Set Ws = CreateObject("WScript.Shell")
'To start Notepad maximized
Ws.Run "Notepad",3
WScript.Sleep 1000
intTextLen = Len(strText)
For x = 1 to intTextLen
strTempText = Mid(strText,x,1)
Ws.Sendkeys strTempText
WScript.Sleep intPause
Next
End Sub
'------------------------------------------
来源:https://stackoverflow.com/questions/52069998/single-line-input-vbs-autotyper