Set args=WScript.Arguments
'参数1为窗口标题字符串，参数2为发送按键，参数3为检测次数
If args.Count=3 Then
    str=args(0)
    key=args(1)
    num=args(2)
Else WScript.Quit(0) End If

Dim objShell
Set objShell = CreateObject("Wscript.Shell")

Dim Count:Count = 0
For i = 1 To num
    Wscript.Sleep 250 '检测间隔 250 毫秒
    If objShell.AppActivate(str) Then
        objShell.SendKeys key
        Wscript.Sleep 1000
        objShell.SendKeys "{ESC}"
        Wscript.Sleep 250
        Set objShell = Nothing
        Exit For
    End If
    Count = Count + 1
Next