Jump to content

How to sleep after every send


leuce
 Share

Recommended Posts

Hello everyone

I have a lot of "Send" actions in my script, and I want the script to sleep for a period of time after every "Send". I don't want to have to add "Sleep (1000)" after every line that contains "Send", though. Is there a way that I can create a separate function that performs the Send action and then the Sleeps action? And if so, can you show me how, please?

For example, instead of:

Send ("^c")
Sleep ("1000")
I would want to be able to just write:

SleepSend ("^c", 1000)
... knowing that the script will send "^c" and then sleep for 1000.

Thanks

Samuel

Edited by leuce
Link to comment
Share on other sites

If it is the same every time you could do this ...

func _sleepSend ()
Send(""^c")
Sleep(1000)
EndFunc

Then you would just type _sleepSend() to use it.

If it could be different every time you could so something like this:

func _sleepSend ($sendvar)
Send($sendvar)
Sleep(1000)
EndFunc

In this case you would type in the stuff to send within the parenthesis as you had in your example

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

If it is the same every time you could do this...

Thanks! I've always wondered how to do this :-)

I now have a related question, though. If this is the function:

Func _sleepSend ($sendvar, $sleepvar)
Send ($sendvar)
Sleep($sleepvar)
EndFunc
....and I want the script to know that if I don't specify the sleepvar, then the sleepvar should be "1000", how would I do that?

I mean, if I used:

_sleepSend ("^c", 2000)
then it should send ^c and sleep for 2 seconds, but if I used:

_sleepSend ("^c")
then it should send ^c and sleep for 1 second (the default sleep).

Thanks again.

Samuel

Link to comment
Share on other sites

That would be an optional parameter.  You should be able to say

Func _sleepSend ($sendvar [,$sleepvar=1000])

Then you can override that default value with a different number.  Otherwise, it will be 1000.

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

  • Moderators

leuce,

Or you could just use the Opt("SendKeyDelay" command to let AutoIt do the hard work for you. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

If your script is a bit buggy due to send not working right (fails for various reasons like the correct window is not active) have you looked at controlsend?

Thanks, but I need to be able to adjust the sleep time because the script interacts with a program that sometimes need more time to respond. It is a Java program, so ControlSend can't be used.

Link to comment
Share on other sites

Another question for you- if your script is a bit buggy due to send not working right (fails for various reasons like the correct window is not active) have you looked at controlsend?

 

also,

SendKeepActive() can be of use in that cases...

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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...