首页 > 解决方案 > VBScript 使用 SendKeys 发送新行的行为很奇怪

问题描述

我正在编写一个非常简单的 VBS 脚本,但遇到了一个非常奇怪的问题:

我最初使用的是这段代码:

Set wshShell=wscript.CreateObject("WScript.Shell")

WScript.Sleep(2000)
Dim i
i = 0
Dim val
val = 25

Do While i < 5
  wshshell.SendKeys("What the")
  WScript.Sleep(val)
  wshshell.SendKeys("{ENTER}")
  WScript.Sleep(val)
  i = i + 1
Loop

但由于某种原因,输出是这样的:

What theWhat theWhat theWhat theWhat the

但是当我改变这个时:

wshshell.SendKeys("What the")

对此:

wshshell.SendKeys("What the ")

它工作正常并输出:

What the 
What the 
What the 
What the 
What the 

是什么原因造成的?我对为什么会发生这种情况感到非常困惑。谢谢。

标签: shellvbscriptwshsendkeys

解决方案


推荐阅读