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

时间:2016-07-09 12:33:31

标签: 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.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"

这很好但是耗时太多了。那我怎么能做同样的事情呢 没有这么多行。

注意:我不知道编码,所以你可以用基础知识解释。

3 个答案:

答案 0 :(得分:0)

怀疑,阅读文档,例如SendKeys Method

  

要发送空格,请发送字符串" &#34 ;.   您可以使用SendKeys一次发送多个击键次数。为此,请创建表示a的复合字符串参数   通过将序列中的每个击键附加到的键击序列   它之前的那个。例如,要发送击键a,b和c,   你会发送字符串参数" abc"。

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe", 3
WScript.Sleep 500            ' give Notepad enough time to start and activate its window
WshShell.SendKeys ". Let's make an example"
WScript.Sleep 500

答案 1 :(得分:0)

您可以使用此代码:)

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 

答案 2 :(得分:0)

好的,谢谢大家!我设法为自己建立了一个程序!如果有人想要使用vbscript逐个显示字母,那么这是download

的程序