如何使用vbscript在记事本中逐个显示字母

如何使用vbscript在记事本中逐个显示字母,vbscript,Vbscript,这是我在Stackoverflow的第一篇文章。我不知道如何开始,但这里是 我的问题:我正在为一个使用vbscript的rpg游戏工作。我在用记事本 这些字母是这样一个接一个出现的: Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "notepad.exe", 3 WshShell.SendKeys ". L" WScript.Sleep(100) WshShell.SendKeys "e" WScript.Sl

这是我在Stackoverflow的第一篇文章。我不知道如何开始,但这里是 我的问题:我正在为一个使用vbscript的rpg游戏工作。我在用记事本 这些字母是这样一个接一个出现的:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe", 3
WshShell.SendKeys ". L"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "t'"
WScript.Sleep(100)
WshShell.SendKeys "s"
WScript.Sleep(100)
WshShell.SendKeys " m"
WScript.Sleep(100)
WshShell.SendKeys "a"
WScript.Sleep(100)
WshShell.SendKeys "k"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys " a"
WScript.Sleep(100)
WshShell.SendKeys "n"
WScript.Sleep(100)
WshShell.SendKeys " e"
WScript.Sleep(100)
WshShell.SendKeys "x"
WScript.Sleep(100)
WshShell.SendKeys "a"
WScript.Sleep(100)
WshShell.SendKeys "m"
WScript.Sleep(100)
WshShell.SendKeys "p"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys "e:"
WScript.Sleep(100)
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{ENTER}"
WScript.Sleep(100)
WshShell.SendKeys "Y"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "u"
WScript.Sleep(100)
WshShell.SendKeys " a"
WScript.Sleep(100)
WshShell.SendKeys "r"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys " i"
WScript.Sleep(100)
WshShell.SendKeys "n"
WScript.Sleep(100)
WshShell.SendKeys " a "
WScript.Sleep(100)
WshShell.SendKeys "f"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "r"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "s"
WScript.Sleep(100)
WshShell.SendKeys "t"
WScript.Sleep(100)
WshShell.SendKeys " w"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "t"
WScript.Sleep(100)
WshShell.SendKeys "h"
WScript.Sleep(100)
WshShell.SendKeys " l"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "m"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "t"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "d"
WScript.Sleep(100)
WshShell.SendKeys " r"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "s"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "u"
WScript.Sleep(100)
WshShell.SendKeys "r"
WScript.Sleep(100)
WshShell.SendKeys "c"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "s."
WScript.Sleep(100)
WshShell.SendKeys " W"
WScript.Sleep(100)
WshShell.SendKeys "h"
WScript.Sleep(100)
WshShell.SendKeys "a"
WScript.Sleep(100)
WshShell.SendKeys "t"
WScript.Sleep(100)
WshShell.SendKeys " w"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys " y"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "u"
WScript.Sleep(100)
WshShell.SendKeys " d"
WScript.Sleep(100)
WshShell.SendKeys "o?"
WScript.Sleep(100)
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "1-"
WScript.Sleep(100)
WshShell.SendKeys "I"
WScript.Sleep(100)
WshShell.SendKeys " w"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys " t"
WScript.Sleep(100)
WshShell.SendKeys "r"
WScript.Sleep(100)
WshShell.SendKeys "y"
WScript.Sleep(100)
WshShell.SendKeys " t"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys " f"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "n"
WScript.Sleep(100)
WshShell.SendKeys "d"
WScript.Sleep(100)
WshShell.SendKeys " s"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "m"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys " r"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "s"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "u"
WScript.Sleep(100)
WshShell.SendKeys "r"
WScript.Sleep(100)
WshShell.SendKeys "c"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys "s."
WScript.Sleep(100)
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "2-"
WScript.Sleep(100)
WshShell.SendKeys "I"
WScript.Sleep(100)
WshShell.SendKeys " w"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys " b"
WScript.Sleep(100)
WshShell.SendKeys "u"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys "d"
WScript.Sleep(100)
WshShell.SendKeys " a "
WScript.Sleep(100)
WshShell.SendKeys "s"
WScript.Sleep(100)
WshShell.SendKeys "m"
WScript.Sleep(100)
WshShell.SendKeys "a"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys "l"
WScript.Sleep(100)
WshShell.SendKeys " h"
WScript.Sleep(100)
WshShell.SendKeys "o"
WScript.Sleep(100)
WshShell.SendKeys "u"
WScript.Sleep(100)
WshShell.SendKeys "s"
WScript.Sleep(100)
WshShell.SendKeys "e"
WScript.Sleep(100)
WshShell.SendKeys " w"
WScript.Sleep(100)
WshShell.SendKeys "i"
WScript.Sleep(100)
WshShell.SendKeys "t"
WScript.Sleep(100)
WshShell.SendKeys "h"
WScript.Sleep(100)
WshShell.SendKeys " m"
WScript.Sleep(100)
WshShell.SendKeys "y"
这样做很好,但太费时了。那么我怎么能做同样的事情呢 没有那么多的台词

注:我不知道编码,因此您可以用基本知识进行解释。

如有疑问,请阅读文档,例如:

要发送空格,请发送字符串。 您可以使用SendKeys一次发送多个击键。为此,请创建一个表示 通过将序列中的每个击键附加到 前面的那个。例如,要发送击键a、b和c, 您将发送字符串参数abc


您可以使用以下代码:

Set Ws = CreateObject("WScript.Shell")
Ws.run "Notepad.exe"
wscript.sleep 1000
ws.AppActivate "Notepad"
Msg = "HELLO !"& vbCRLF &_
"I'M WRITING RIGHT NOW THIS SPECIAL MESSAGE FOR YOU Letter by Letter !"& vbCRLF &_
"Good luck and Good bye from Hackoo !"

For x = 1 To Len(Msg)
    WScript.Sleep 100
    Ws.SendKeys Mid(Msg,x,1)
    WScript.Sleep 100
Next

Call SpeakVoice(Msg)

'--SpeakVoice--
Function SpeakVoice(msg)
Dim voice
Set Voice=CreateObject("SAPI.SpVoice")
voice.speak msg
end Function 

好的,谢谢大家!我设法为自己建立了一个程序!如果有人想用vbscript逐个显示字母,这里是重新开始的程序,不使用SendKeys将文本放入记事本?相反,你可以制作一个控制台程序。@crashmstr,除非他们的目标是创建世界上第一个记事本RPG;pI不明白除了重复的代码外,Else还能做什么?SpeakVoice部分是否与OPs原始问题相关?@Lankymart不,这只是我的一个奖励,Lol会延迟每次按键,还是在激活时将所有文本写入记事本?
Set Ws = CreateObject("WScript.Shell")
Ws.run "Notepad.exe"
wscript.sleep 1000
ws.AppActivate "Notepad"
Msg = "HELLO !"& vbCRLF &_
"I'M WRITING RIGHT NOW THIS SPECIAL MESSAGE FOR YOU Letter by Letter !"& vbCRLF &_
"Good luck and Good bye from Hackoo !"

For x = 1 To Len(Msg)
    WScript.Sleep 100
    Ws.SendKeys Mid(Msg,x,1)
    WScript.Sleep 100
Next

Call SpeakVoice(Msg)

'--SpeakVoice--
Function SpeakVoice(msg)
Dim voice
Set Voice=CreateObject("SAPI.SpVoice")
voice.speak msg
end Function