Jump to content

Pause between Sends


Recommended Posts

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

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 @ MPCS

EDIT: Reworded to be nice.

Edited by Matt @ MPCS
Link to comment
Share on other sites

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)
Next

I havent tested it but its the concept I am trying to show. Hope that helps.

*** Matt @ MPCS

EDIT: sorry forgot to put the Sleeps into the loop.

Edited by Matt @ MPCS
Link to comment
Share on other sites

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

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.

<{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 )
Next

This 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

  • Administrators

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
Link to comment
Share on other sites

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

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 by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

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

<{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 also

do 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

Link to comment
Share on other sites

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

<{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] )
Next

I dont know if this works but the logic is sound.

*** Matt @ MPCS

Link to comment
Share on other sites

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] )
Next

Again it isn't tested but I know this syntax works with AutoIt.

*** Matt @ MPCS

Link to comment
Share on other sites

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 by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

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 by MikeOsdx
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...