Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 单线输入VBS自动打字机_Vbscript_Wsh - Fatal编程技术网

Vbscript 单线输入VBS自动打字机

Vbscript 单线输入VBS自动打字机,vbscript,wsh,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.Se

我目前正试图在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

我给你举了一个小例子,可以像打字机一样一个字母一个字母地打字

希望这就是你想要的

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
'------------------------------------------

好的解决方案。OP的措辞有点误导,但仍然是一个很好的解决方案。很好的一个@Hackoo+1为了澄清,OP的代码是有效的。他们只是想要一种更有效的方式来提供输入,而不是指定单个的
SendKeys()
方法调用。