我目前正在尝试在VBS中创建自动打字机,但我不知道如何轻松输入要输入的内容。现在,这就是我的代码的样子:
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"
但是我真的希望我的代码能够将所有文本都自动输入到一行中,而不必为每个字母重复SendKeys
。
答案 0 :(得分:3)
我为您提供了一个小示例,可以作为打字机逐个字母输入
。希望这是您想要的!
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
'------------------------------------------