leuce Posted December 27, 2014 Share Posted December 27, 2014 (edited) Hello everyoneI 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.ThanksSamuel Edited December 27, 2014 by leuce Link to comment Share on other sites More sharing options...
Jfish Posted December 27, 2014 Share Posted December 27, 2014 (edited) 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 December 27, 2014 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 More sharing options...
leuce Posted December 27, 2014 Author Share Posted December 27, 2014 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 More sharing options...
Jfish Posted December 27, 2014 Share Posted December 27, 2014 (edited) 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 December 27, 2014 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 More sharing options...
Moderators Melba23 Posted December 27, 2014 Moderators Share Posted December 27, 2014 leuce,Or you could just use the Opt("SendKeyDelay" command to let AutoIt do the hard work for you. M23 Jfish 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Bert Posted December 27, 2014 Share Posted December 27, 2014 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? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
leuce Posted December 27, 2014 Author Share Posted December 27, 2014 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 More sharing options...
Gianni Posted December 27, 2014 Share Posted December 27, 2014 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... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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