VBScript不允许“{SPACE}”

时间:2015-03-23 04:56:47

标签: vbscript

我正在创建一个.vbs脚本,允许我在其他人的Notepad ++应用程序上键入一条长消息,以便我可以告诉那个人他需要做什么,因为他没有太多经验计算机。

所以这是脚本:

Set shl = CreateObject("Shell.Application")
Set strt = CreateObject("WScript.Shell")
MsgBox "Running Script Maker.."
shl.ShellExecute "notepad++.exe", , "C:\Program Files\Notepad++"
Wscript.sleep 2000
strt.SendKeys "H"
Wscript.sleep 100
strt.SendKeys "e"
Wscript.sleep 100
strt.SendKeys "l"
Wscript.sleep 100
strt.SendKeys "l"
Wscript.sleep 100
strt.SendKeys "o."
Wscript.sleep 3000
strt.SendKeys "{ENTER}"
strt.SendKeys "Y"
Wscript.sleep 100
strt.SendKeys "o"
Wscript.sleep 100
strt.SendKeys "u"
Wscript.sleep 100
strt.SendKeys "{SPACE}"
Wscript.sleep 100
strt.SendKeys "m"
Wscript.sleep 100
strt.SendKeys "i"
Wscript.sleep 100
strt.SendKeys "g"
Wscript.sleep 100
strt.SendKeys "h"
Wscript.sleep 100
strt.SendKeys "t"
Wscript.sleep 100
strt.SendKeys "{SPACE}"
Wscript.sleep 100
strt.SendKeys "t"
Wscript.sleep 100
strt.SendKeys "h"
Wscript.sleep 100
strt.SendKeys "i"
Wscript.sleep 100
strt.SendKeys "n"
Wscript.sleep 100
strt.SendKeys "k"
Wscript.sleep 100
strt.SendKeys "{SPACE}"
Wscript.sleep 100
strt.SendKeys "t"
Wscript.sleep 100
strt.SendKeys "h"
Wscript.sleep 100
strt.SendKeys "a"
Wscript.sleep 100
strt.SendKeys "t"
Wscript.sleep 100

直到脚本到达" {SPACE}" 在"你"之后消息的一部分。 任何类型的解决方案都会很方便。我已经把这个问题惹恼了好几分钟。

1 个答案:

答案 0 :(得分:1)

"{SPACE}"似乎是not actually supported,该格式往往是无法直接表示为键盘字符的击键。

在您的情况下,您只需使用" ",它似乎工作正常。


可能也想考虑重构你的代码以使它更易于维护,例如:

sub out (pStrt, pStr, pDelay1, pDelay2)
    pos = 1
    while pos <= len (pStr)
        sz = 1
        if mid (pStr, pos, 1) = "{" then
            sz = instr (pos + 1, pStr, "}") + 1
        end if
        pStrt.SendKeys mid (pStr, pos, sz)
        WScript.sleep pDelay1
        pos = pos + sz
    wend
    if pDelay2 > pDelay1 then
        WScript.sleep pDelay2 - pDelay1
    end if
end sub

Set shl = CreateObject ("Shell.Application")
Set strt = CreateObject ("WScript.Shell")
shl.ShellExecute "notepad.exe", , "C:\"
Wscript.sleep 2000

out strt, "Hello.{ENTER}", 100, 3000
out strt, "You might think that", 100, 0