This is the script:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; WinSendKeys
; By Ath, 2011-01-24
; Updated 2011-01-25, upx disabled, debug mode writes to .log file, formatted helpmessage a little better
; options:
; -t timeout
; -w windowname
; -d : Debug mode
; Keystrokes: http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm
$dela = 100 ; msec delay between keystrokes sent
$win = "" ; Name of Window to activate, naming according to these rules: http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm
$dbg = 0 ; Debug mode
$dbgfile = "" ; Write logging to this file
If $CmdLine[0] < 2 Then
ShowHelp()
Else
$p = 1
$n = 1
While $n <= $CmdLine[0]
If ($p = $n) And (StringLeft($CmdLine[$n],1) = "-") Then
If (StringLower($CmdLine[$n]) = "-t") And ($n < $CmdLine[0]) Then
$n = $n + 1
$dela = $CmdLine[$n]
$p = $n + 1
EndIf
If (StringLower($CmdLine[$n])) = "-w" And ($n < $CmdLine[0]) Then
$n = $n + 1
$win = $CmdLine[$n]
$p = $n + 1
EndIf
If StringLower($CmdLine[$n]) = "-d" Then
$dbg = 1
$p = $n + 1
$dbgfile = StringReplace(@ScriptName,".au3",".log")
If $dbgfile = @ScriptName Then
$dbgfile = StringReplace(@ScriptName,".exe",".log")
EndIf
EndIf
EndIf
$n = $n + 1
WEnd
If $win = "" Then
$win = $CmdLine[$p]
$p = $p + 1
EndIf
If Not $win = "" Then
If $dbg Then writeLogLine("Window: " & $win & @CRLF)
AutoItSetOption("WinTitleMatchMode",2)
$w = WinActivate($win, "")
If $dbg Then writeLogLine("Windowhandle: " & $w)
If $w <> 0 Then
SendKeepActive($w)
For $n = $p to $CmdLine[0]
If $dbg Then writeLogLine("Send: " & $CmdLine[$n] & @CRLF)
Send($CmdLine[$n])
Sleep($dela)
Next
EndIf
EndIf
EndIf
Func ShowHelp()
MsgBox(0,"WinSendKeys : Send keystrokes to a named window","Usage:" & @CRLF _
& "WinSendKeys [-t keydelay] [-d] [-w] <WindowName> <Keystrokes to send>" & @CRLF _
& "-t keydelay = msec value, default 100" & @CRLF _
& "-d = Debug mode, writes extra information to WinSendKeys.log" & @CRLF _
& "-w <WindowName> = name value as defined here:" & @CRLF _
& @TAB & "www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm" & @CRLF _
& "<Keystrokes> = Keystroke values as defined here:" & @CRLF _
& @TAB & "www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm" & @CRLF)
EndFunc
Func writeLogLine($message)
; Write a line to the logfile, with a prefix of "yyyy-MM-dd hh:mm:ss.msec, ", as the generic _FileWriteLog function gave errors
Local $openLogFile = FileOpen($dbgfile,1)
If $openLogFile > -1 Then
FileWriteLine($openLogFile,@YEAR&"-"&@MON&"-"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC&"."&StringFormat("%03d",@MSEC)&", " & $message)
FileClose($openLogFile)
EndIf
EndFunc