0

I'm trying to write a simple script to fill in login details on a program that requires signing in using a keyboard shortcut.

set wshshell = wscript.CreateObject("wscript.shell")
WshShell.SendKeys "username{tab}passowrd{enter}"

This works as desired on my work computer (xp) but on my home computer (windows 8) the keyboard shortcut deactivates the current window so that the details are not entered. Any help would be greatly appreciated.

4

1 回答 1

0

您可能需要查看 shell 的 AppActivate 方法。你可以这样写:

boolSuccess = False
do until boolSuccess = True
    boolSuccess = WshShell.AppActivate("AppName")
    WshShell.sleep 500
loop    
WshShell.SendKeys "username{tab}password{enter}"

这会将焦点移动到您的目标应用程序,然后发送密钥。可悲的是,您可能需要在 AppActivate 和 SendKeys 之间“休眠”,以确保您的目标应用程序有时间接收焦点。

于 2013-07-18T21:10:02.390 回答