单行输入 VBS 自动打字机

Bre*_*mer 4 vbscript wsh

我目前正在尝试在 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"
Run Code Online (Sandbox Code Playgroud)

但我真的希望我的代码能够在一行中自动输入所有文本,而不必SendKeys为每个字母重复输入。

Hac*_*koo 5

我为你做了一个小例子,它可以像打字机一样一个字母一个字母地打字。

希望这是你正在寻找的!

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
'------------------------------------------
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

  • 很好的解决方案。OP 的措辞有点误导,但仍然是很好的解决方案。 (2认同)