Main Area and Open Discussion > General Software Discussion
Simple Commandline to send Keystrokes (WinSendKeys)
Ath:
Ok, I've not searched the internet, but just wanted to write a little AutoIt3 script that does exactly that for you:
Latest release & download moved to separate thread
WinSendKeys [-t Timedelay] [-d] [-w] <WindowName> <Keystrokes to send>
It takes 3 options and as much parameters (keystrokes) as you would like:
- -w <WindowName> : A window name or expression, as detailed in this page
- -t <Timedelay> : A number of milliseconds to wait between each set of keystrokes to send
- -d : Debug mode, writes some info into WinSendKeys.log in the current directory
- <Keystrokes to send> : Any amount of keystrokes that will fit the commandline, using the syntax from this page
(Be sure to double up any ^ marker for Control as it has a special feature in cmd.exe, so ^^n becomes Ctrl-N)
Updated to a newer version below, 1.0 is hiding here...This is the script:
--- Code: AutoIt ---#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 EndIfEndIf 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) EndIfEndFunc
The compiled/non-upx'd exe is attached (updated: 2011-01-26)
wraith808:
Ath, I think we're not upx'ing them anymore because they're more likely to show up AV-positive if they are, so you might want to re-upload non-upx'd version.
See notification here.
Ath:
Ath, I think we're not upx'ing them anymore because they're more likely to show up AV-positive if they are, so you might want to re-upload non-upx'd version.
See notification here.
-wraith808 (January 24, 2011, 09:29 PM)
--- End quote ---
Oh, I missed/forgot that announcement, though I read a lot about upx'ed exe's being flagged by virusscanners :-[
Fixed it. And that's the second reason I published the source (first being this free-for-all), so anybody not trusting external exe's can re-compile it in a trusted environment.
Ath:
I updated the original script, to write to WinSendKeys.log when -d parameter is used, effectively re-enabling this option. The compiled attachment is ofcourse also updated.
Thanks a ton in advance!
-Split_e (January 23, 2011, 06:50 PM)
--- End quote ---
This might have triggered me, even though I just yet read close enough to spot it :-*
Now let's wait for the OP to comment on this.
Split_e:
Thanks so much guys! I have been following this and the other thread, and I just spent some time tinkering with it. Unfortunately, I'm having some issues. I'm pretty new to this stuff (I'm an engineering major, so my programming background is just VB6 and C++, some javascript). Can you tell me where I'm going wrong with this?
My "Tool Properties" window fields are:
Title: WinSendKeys
Program: C:\Users\Tyler\Books\Software\Ripping books\WinSendKeys.exe
Working Dir: C:\Users\Tyler\Books\Software\Ripping books\
Parameters: (blank)
I've tried a million variations of the commanline, but to be honest, I'm basically guessing. Of the many:
WinSendKeys <50> <"Materials"> <"{RIGHT}">
WinSendKeys [-t 50] [-d] [-w] <"Materials"> <"{RIGHT}">
WinSendKeys [-t 50] [-d] [-w] "Materials" "{RIGHT}"
The window is "Materials Science and Engineering: An Introduction, 8th Edition - CourseSmart Bookshelf". I've tried using the full name and different lengths, different times, different keys... :/
Any help is so very much appreciated!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version