我正在尝试创建一个VBA脚本,它将打开一个Putty窗口,输入用户信息(用户名,密码等),按下(向下箭头)到正确的菜单选项,然后打开该菜单选项。
该脚本工作正常,但我无法使用putty使keydown函数正常工作。脚本是否失去了对窗口的关注?我是否正确使用了keydown功能?有没有更好的方法来写这个动作?
Sub Putty()
'
Dim puttyID As String
puttyID = Shell("C:\Program Files (x86)\PuTTY\putty.exe", vbNormalFocus)
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
SendKeys "information", True
SendKeys "{ENTER}, True"
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 3
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
SendKeys "user", True
SendKeys "~", True
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
SendKeys "password", True
SendKeys "~", True
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
SendKeys "ID", True
SendKeys "~", True
SendKeys "~", True
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
SendKeys "2", True
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
SendKeys "{Down}", True
SendKeys "{Down}", True
SendKeys "~", True
End Sub
答案 0 :(得分:0)
该应用可能没有足够的时间来响应SendKeys。我建议把:
<强>的DoEvents 强>
紧跟任何似乎被忽略的SendKeys语句之后的语句。