BigDaddyO Posted October 1, 2004 Share Posted October 1, 2004 I have a script that sends commands to a old slow program. I have to Enter some text then arrow or tab then enter more text. I have had to put in 35 lines of code because I have to put a sleep(500) after each arrow or tab before the program will allow more text input. I am wondering if there is a way to put a pause/sleep command within the Send command. I didn't find anything in the help file and i already tried send("This " & sleep(500) & "is " & Sleep(500) & "a pause") but that doesn't work either. Mike Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 1, 2004 Share Posted October 1, 2004 (edited) I have a script that sends commands to a old slow program. I have to Enter some text then arrow or tab then enter more text. I have had to put in 35 lines of code because I have to put a sleep(500) after each arrow or tab before the program will allow more text input. I am wondering if there is a way to put a pause/sleep command within the Send command. I didn't find anything in the help file and i already tried send("This " & sleep(500) & "is " & Sleep(500) & "a pause") but that doesn't work either.Mike<{POST_SNAPBACK}>Look at the manual for the SendKeyDelay option. I think that is what you are looking for.*** Matt @ MPCSEDIT: Reworded to be nice. Edited October 1, 2004 by Matt @ MPCS Link to comment Share on other sites More sharing options...
BigDaddyO Posted October 1, 2004 Author Share Posted October 1, 2004 The SendKeyDelay is interesting but with the amount of Text i have to enter it will take several hours to run the script with a half second delay between keystrokes. Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 1, 2004 Share Posted October 1, 2004 (edited) You could do what you have above:I am wondering if there is a way to put a pause/sleep command within the Send command. I didn't find anything in the help file and i already tried send("This " & sleep(500) & "is " & Sleep(500) & "a pause") but that doesn't work either.Except you will need to seperate it onto individual lines. like you say you already have. You could also try to put the string you need into a variable and loop the variable like this:$tmpString = "This is a pause" For $i = 1 to StringLen( $tmpString ) Step 5 Send( StringMid( $tmpString, $i, 5 ) ) Sleep(3000) NextI havent tested it but its the concept I am trying to show. Hope that helps.*** Matt @ MPCSEDIT: sorry forgot to put the Sleeps into the loop. Edited October 1, 2004 by Matt @ MPCS Link to comment Share on other sites More sharing options...
BigDaddyO Posted October 1, 2004 Author Share Posted October 1, 2004 Here is a small sample of the code Send("!jn") Sleep(500) Send("!w") Sleep(500) Send("{DOWN}") Sleep(500) Send("{DOWN}") Sleep(500) Send("{Right}") Sleep(500) Send("{~}") Sleep(500) Send("{Right}") Sleep(500) Send("{APPSKEY}") Sleep(500) Send("s") Sleep(500) Send("{DOWN}") Sleep(500) Send("{APPSKEY}") Sleep(500) Send("d") Sleep(500) Send("!r{TAB}") Sleep(500) Send("c:\") Sleep(500) Send("!s") Because of the variance of the sends and the amount of pauses it takes to get it to run right I don't think setting a variable for what I am going to send will work for me. maybe Jon could add this ability to the next version of AutoIT, it would certinly reduce the size of alot of my scripts. Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 1, 2004 Share Posted October 1, 2004 Here is a small sample of the codeSend("!jn") Sleep(500) Send("!w") Sleep(500) Send("{DOWN}") Sleep(500) Send("{DOWN}") Sleep(500) Send("{Right}") Sleep(500) Send("{~}") Sleep(500) Send("{Right}") Sleep(500) Send("{APPSKEY}") Sleep(500) Send("s") Sleep(500) Send("{DOWN}") Sleep(500) Send("{APPSKEY}") Sleep(500) Send("d") Sleep(500) Send("!r{TAB}") Sleep(500) Send("c:\") Sleep(500) Send("!s")Because of the variance of the sends and the amount of pauses it takes to get it to run right I don't think setting a variable for what I am going to send will work for me. maybe Jon could add this ability to the next version of AutoIT, it would certinly reduce the size of alot of my scripts.<{POST_SNAPBACK}>This can be reduced drastically... just try this:$strCommands = "!jn|!w|{DOWN}|{DOWN}|{Right}|{~}|{Right}|{APPSKEY}|s|{DOWN}|{APPSKEY}|d|!r{TAB}|c:\|!s" $arrCommands = StringSplit( $strCommands, "|" ) For $i = 1 to $arrCommands[0] Send( $arrCommands[i] ) Sleep( 500 ) NextThis reduced a 30+ line script to an 8 line script (including whitespace)... no need for a new function.*** Matt @ MPCS Link to comment Share on other sites More sharing options...
Administrators Jon Posted October 1, 2004 Administrators Share Posted October 1, 2004 Because of the variance of the sends and the amount of pauses it takes to get it to run right I don't think setting a variable for what I am going to send will work for me. maybe Jon could add this ability to the next version of AutoIT, it would certinly reduce the size of alot of my scripts.MySend("!jn") MySend("!w") MySend("{DOWN}") MySend("{DOWN}") MySend("{Right}") MySend("{~}") MySend("{Right}") MySend("{APPSKEY}") MySend("s") MySend("{DOWN}") MySend("{APPSKEY}") MySend("d") MySend("!r{TAB}") MySend("c:\") MySend("!s") Func MySend($text) Send($text) Sleep(500) EndFunc Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 1, 2004 Share Posted October 1, 2004 MySend("!jn") MySend("!w") MySend("{DOWN}") MySend("{DOWN}") MySend("{Right}") MySend("{~}") MySend("{Right}") MySend("{APPSKEY}") MySend("s") MySend("{DOWN}") MySend("{APPSKEY}") MySend("d") MySend("!r{TAB}") MySend("c:\") MySend("!s") Func MySend($text) Send($text) Sleep(500) EndFunc<{POST_SNAPBACK}> Mine is still shorter! lol Yours is inventive though Jon... good thinkin!*** Matt @ MPCS Link to comment Share on other sites More sharing options...
modeler2us Posted October 2, 2004 Share Posted October 2, 2004 Mine is still shorter! lol Yours is inventive though Jon... good thinkin!*** Matt @ MPCS<{POST_SNAPBACK}>Wow - that was intuitive! Thanks as well!!! Link to comment Share on other sites More sharing options...
scriptkitty Posted October 3, 2004 Share Posted October 3, 2004 (edited) Best part of this would be less lines: $arrCommands = StringSplit( "!jn|!w|{DOWN}|{DOWN}|{Right}|{~}|{Right}|{APPSKEY}|s|{DOWN}|{APPSKEY}|d|!r{TAB}|c:\|!s", "|" ) For $i = 1 to $arrCommands[0] Send( $arrCommands[i] ) Sleep( 500 ) Next Best part of a function would be you could customise waits. MySend("!jn",500) MySend("!w",500) MySend("{DOWN}",300) MySend("{DOWN}",500) MySend("{Right}",600) MySend("{~}",500) MySend("{Right}",700) MySend("{APPSKEY}",500) MySend("s",500) MySend("{DOWN}",500) MySend("{APPSKEY}",100) MySend("d",500) MySend("!r{TAB}",500) MySend("c:\",500) MySend("!s",500) Func MySend($text,$time) Send($text) Sleep($time) EndFunc So I like both of them equally. Look beyond the box. edit well actually... $arrCommands = StringSplit( "!jn:5|!w:5|{DOWN}:5|{DOWN}:6|{Right}:5|{~}:5|{Right}:7|{APPSKEY}:5|s:6|{DOWN}:5|{APPSKEY}:5|d:5|!r{TAB}:5|c:\:5|!s:5", "|" ) For $i = 1 to $arrCommands[0] Send( StringTrimRight($arrCommands[$i],2) ) Sleep( StringRight($arrCommands[$i],1)*100 ) Next Edited October 3, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
normeus Posted October 3, 2004 Share Posted October 3, 2004 Best part of this would be less lines:$arrCommands = StringSplit( "!jn|!w|{DOWN}|{DOWN}|{Right}|{~}|{Right}|{APPSKEY}|s|{DOWN}|{APPSKEY}|d|!r{TAB}|c:\|!s", "|" ) For $i = 1 to $arrCommands[0] Send( $arrCommands[i] ) Sleep( 500 ) NextBest part of a function would be you could customise waits.MySend("!jn",500) MySend("!w",500) MySend("{DOWN}",300) MySend("{DOWN}",500) MySend("{Right}",600) MySend("{~}",500) MySend("{Right}",700) MySend("{APPSKEY}",500) MySend("s",500) MySend("{DOWN}",500) MySend("{APPSKEY}",100) MySend("d",500) MySend("!r{TAB}",500) MySend("c:\",500) MySend("!s",500) Func MySend($text,$time) Send($text) Sleep($time) EndFuncSo I like both of them equally. Look beyond the box.edit well actually...$arrCommands = StringSplit( "!jn:5|!w:5|{DOWN}:5|{DOWN}:6|{Right}:5|{~}:5|{Right}:7|{APPSKEY}:5|s:6|{DOWN}:5|{APPSKEY}:5|d:5|!r{TAB}:5|c:\:5|!s:5", "|" ) For $i = 1 to $arrCommands[0] Send( StringTrimRight($arrCommands[$i],2) ) Sleep( StringRight($arrCommands[$i],1)*100 ) Next<{POST_SNAPBACK}>beautiful code " using a function" and for next loop with array of send and delay GENIUS!!! I am sending keystrokes to a set of old cobol programs and you might want to alsodo this at the start of your script:AutoItSetOption("SendKeyDelay", 2) ;default is 5 but 2 works better for me (faster)AutoItSetOption("SendKeyDownDelay", 2) ; default is 1 so 2 keeps the key pressed a little longer http://www.autoitscript.com/autoit3/scite/...iTe4AutoIt3.exe Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 3, 2004 Share Posted October 3, 2004 Best part of this would be less lines:$arrCommands = StringSplit( "!jn|!w|{DOWN}|{DOWN}|{Right}|{~}|{Right}|{APPSKEY}|s|{DOWN}|{APPSKEY}|d|!r{TAB}|c:\|!s", "|" ) For $i = 1 to $arrCommands[0] Send( $arrCommands[i] ) Sleep( 500 ) NextBest part of a function would be you could customise waits.MySend("!jn",500) MySend("!w",500) MySend("{DOWN}",300) MySend("{DOWN}",500) MySend("{Right}",600) MySend("{~}",500) MySend("{Right}",700) MySend("{APPSKEY}",500) MySend("s",500) MySend("{DOWN}",500) MySend("{APPSKEY}",100) MySend("d",500) MySend("!r{TAB}",500) MySend("c:\",500) MySend("!s",500) Func MySend($text,$time) Send($text) Sleep($time) EndFuncSo I like both of them equally. Look beyond the box.edit well actually...$arrCommands = StringSplit( "!jn:5|!w:5|{DOWN}:5|{DOWN}:6|{Right}:5|{~}:5|{Right}:7|{APPSKEY}:5|s:6|{DOWN}:5|{APPSKEY}:5|d:5|!r{TAB}:5|c:\:5|!s:5", "|" ) For $i = 1 to $arrCommands[0] Send( StringTrimRight($arrCommands[$i],2) ) Sleep( StringRight($arrCommands[$i],1)*100 ) Next<{POST_SNAPBACK}>This is a good idea but it creates a limitation on the wait between 100-900 only on even hundreds. It might be better if you did the parsing a bit different:$arrCommands = StringSplit( "!jn:5|!w:5|{DOWN}:5|{DOWN}:6|{Right}:5|{~}:5|{Right}:7|{APPSKEY}:5|s:6|{DOWN}:5|{APPSKEY}:5|d:5|!r{TAB}:5|c:\:5|!s:5", "|" ) For $i = 1 to $arrCommands[0] Send( StringSplit($arrCommands[$i], ":")[1] ) Sleep( StringSplit($arrCommands[$i], ":")[2] ) NextI dont know if this works but the logic is sound.*** Matt @ MPCS Link to comment Share on other sites More sharing options...
Valik Posted October 3, 2004 Share Posted October 3, 2004 Some languages (C\C++ come to mind) thats possible, but not with AutoIt. Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted October 3, 2004 Share Posted October 3, 2004 Some languages (C\C++ come to mind) thats possible, but not with AutoIt.<{POST_SNAPBACK}>I hadn't ever tested that in AutoItbut it is easy enough to change:$arrCommands = StringSplit( "!jn:5|!w:5|{DOWN}:5|{DOWN}:6|{Right}:5|{~}:5|{Right}:7|{APPSKEY}:5|s:6|{DOWN}:5|{APPSKEY}:5|d:5|!r{TAB}:5|c:\:5|!s:5", "|" ) For $i = 1 to $arrCommands[0] subArray = SplitString( $arrCommands[$i], ":" ) Send( subArray[1] ) Sleep( subArray[2] ) NextAgain it isn't tested but I know this syntax works with AutoIt.*** Matt @ MPCS Link to comment Share on other sites More sharing options...
scriptkitty Posted October 3, 2004 Share Posted October 3, 2004 (edited) Actually I do this often, and yes you can split an array value. Make sure to put $ in front of your strings and arrays $arrCommands = StringSplit( "!jn:5|!w:5|{DOWN}:5|{DOWN}:6|{Right}:5|{~}:5|{Right}:7|{APPSKEY}:5|s:6|{DOWN}:5|{APPSKEY}:5|d:5|!r{TAB}:5|c:\:5|!s:5", "|" ) For $i = 1 to $arrCommands[0] $subArray = SplitString( $arrCommands[$i], ":" ) Send( $subArray[1] ) Sleep( $subArray[2] ) Next Try this simple explanation. $array=StringSplit("bob:$5|frank:$50,000|joe:0","|") for $i=1 to $array[0] $split=StringSplit($array[$i],":") msgbox(1,$split[1],"Owes me " & $split[2]) next Edit ... Never meant to get so complex, but AutoIt's StringSplit is for strings, so make sure you convert them to get real numeric values out. Sleep function will treat StringSplit values as numbers without conversion. If used for other purposes, you may need to change it to a number, integer, etc. Edited October 3, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
BigDaddyO Posted October 4, 2004 Author Share Posted October 4, 2004 Wow, Thank you all. I never expected this many amazing responses I believe I will be using all of these suggestions in a couple different scripts of mine. Thanks, Mike Link to comment Share on other sites More sharing options...
BigDaddyO Posted October 4, 2004 Author Share Posted October 4, 2004 (edited) OK, I have taken a little bit of everyones code and combined it into something that will work for every one of my scripts. this is sooooo cool. I wrote this up to work with Word XP so I could easily see it run. Opt ("WinTitleMatchMode", 4) Run("C:\Program Files\Microsoft Office\Office10\Winword.exe") If WinWaitActive("classname=OpusApp", "", 10) Then FuncSend("This;500|is;500|A;1000|{TAB}Test;500") EndIf Func FuncSend($Info) $SendArray = StringSplit( $Info, "|" ) For $i = 1 to $SendArray[0] $SendsubArray = StringSplit( $SendArray[$i], ";" ) Send( $SendsubArray[1] ) Sleep( $SendsubArray[2] ) Next EndFunc edit: Changed the ":" to ";" so I could send directory strings such as c:\ Edited October 4, 2004 by MikeOsdx Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now