xPloit Posted September 17, 2010 Share Posted September 17, 2010 I'm just starting to learn how to write programs with AutoIt and due to a general lack of tutorials, progress is rather slow So I'm sorry if this is a very noob question, but I am failing to see the solution. This is also my first script that uses functions so I'm not very comfortable with them yet. The program is just made to spam 2 different messages, with a start and stop button. Once I hit start, the stop button will not work...it keeps going... expandcollapse popup#Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $GUI = GUICreate("Spammer",200,120) GUISetOnEvent($GUI_EVENT_CLOSE,"Close") Global $Message = GUICtrlCreateInput("Message",10,10,180,20) Global $Message1 = GUICtrlCreateInput("Message1",10,40,180,20) Global $Start = GUICtrlCreateButton("Start",10,80,80,30) GUICtrlSetOnEvent($Start,"Start") Global $Stop = GUICtrlCreateButton("Stop",100,80,80,30) GUICtrlSetOnEvent($Stop,"Stop") Global $Proceed = 0 GUISetState() While 1 Sleep(10) WEnd Func Start() $Proceed = 1 TrayTip("Autotalker","Started",2) Sleep(5000) While $Proceed = 1 ControlSend("","","",GUICtrlRead($Message) & "{ENTER}") Sleep(1000) ControlSend("","","",GUICtrlRead($Message1) & "{ENTER}") Sleep(1000) WEnd EndFunc Func Stop() $Proceed = 0 TrayTip("Autotalker","Stopped",2) EndFunc Func Close() Exit EndFunc I am hoping there is an easy fix to this, and I'm guessing there is, but I'm not able to figure it out, haha Thanks, -xPloit 00101101011110000101000001101100011011110110100101110100 Link to comment Share on other sites More sharing options...
hooked Posted September 17, 2010 Share Posted September 17, 2010 try expandcollapse popup#Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $GUI = GUICreate("Spammer",200,120) GUISetOnEvent($GUI_EVENT_CLOSE,"Close") Global $Message = GUICtrlCreateInput("Message",10,10,180,20) Global $Message1 = GUICtrlCreateInput("Message1",10,40,180,20) Global $Start = GUICtrlCreateButton("Start",10,80,80,30) GUICtrlSetOnEvent($Start,"Start") Global $Stop = GUICtrlCreateButton("Stop",100,80,80,30) GUICtrlSetOnEvent($Stop,"Stop") Global $Proceed = 0 GUISetState() While 1 Sleep(10) if $proceed = 1 then _proceed() WEnd Func Start() $Proceed = 1 EndFunc Func _proceed() TrayTip("Autotalker","Started",2) Sleep(5000) While $Proceed = 1 ControlSend("","","",GUICtrlRead($Message) & "{ENTER}") Sleep(1000) ControlSend("","","",GUICtrlRead($Message1) & "{ENTER}") Sleep(1000) WEnd EndFunc Func Stop() $Proceed = 0 TrayTip("Autotalker","Stopped",2) EndFunc Func Close() Exit EndFunc Link to comment Share on other sites More sharing options...
xPloit Posted September 17, 2010 Author Share Posted September 17, 2010 works like a charm! I knew it was an easy fix haha! Thanks! 00101101011110000101000001101100011011110110100101110100 Link to comment Share on other sites More sharing options...
hooked Posted September 17, 2010 Share Posted September 17, 2010 its because another function cant start until the previous one is finished... i would like to know if you can somehow set a "low priority" function, so it can be interrupted by others - see http://www.autoitscript.com/forum/index.php?showtopic=119764&pid=832137&st=0&#entry832137 Link to comment Share on other sites More sharing options...
xPloit Posted September 17, 2010 Author Share Posted September 17, 2010 (edited) That's what i was thinking. I was trying to figure out how to add some sort of check during the "start" function to see if $proceed still equaled 1, but I couldn't get it to work out, lol. I have a new problem now though. I'm trying to add a custom sleep delay for users. I know how to add the drop box and I added the choices I wanted. However, I wanted the options to be seconds, not milliseconds. So how do I change the code to make the choices be in sec, but the actual $Sleep variable to be in ms so that it works right? Global $Sleep = GUICtrlCreateCombo("",100,80,40,40) GUICtrlSetData($Sleep,"1|2|3|4|5|6|7|8|9|10|30|60","0") And then I changed the code below to: Sleep($Sleep) But this way, it would rest for 30ms...not 30 seconds like I want it to EDIT: I got that working. Just changed it from Sleep($Sleep) to Sleep($Sleep*1000) Not sure if there is a better way of doing this, but it works, haha. Now I gotta figure out why $message1 doesn't send {enter} like it should... Edited September 17, 2010 by xPloit 00101101011110000101000001101100011011110110100101110100 Link to comment Share on other sites More sharing options...
xPloit Posted September 17, 2010 Author Share Posted September 17, 2010 Well, just kidding about the timer working...it doesn't work, haha. No matter what option I choose, it does the same sleep time...here's my whole code in case you need it expandcollapse popup#Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $GUI = GUICreate("Spammer",200,170) Global $Timer = GUICtrlCreateLabel("Timer (secs) -",40,80,80,20) Global $Sleep = GUICtrlCreateCombo("",100,80,40,40) GUICtrlSetData($Sleep,"1|2|3|4|5|6|7|8|9|10|30|60","0") GUISetOnEvent($GUI_EVENT_CLOSE,"Close") Global $Message = GUICtrlCreateInput("",10,10,180,20) Global $Message1 = GUICtrlCreateInput("",10,40,180,20) Global $Start = GUICtrlCreateButton("Start",10,120,80,30) GUICtrlSetOnEvent($Start,"Start") Global $Stop = GUICtrlCreateButton("Stop",100,120,80,30) GUICtrlSetOnEvent($Stop,"Stop") Global $Proceed = 0 GUISetState() While 1 Sleep(10) If $Proceed = 1 Then _Proceed() WEnd Func Start() If GUICtrlRead($Message) = "" Then MsgBox(0,"ERROR","You must define your message!") Return ElseIf GUICtrlRead($Message1) = "" Then MsgBox(0,"ERROR","You must define your second message!") Return ElseIf GUICtrlRead($Sleep) = "" Then MsgBox(0,"ERROR","You must define a sleep delay!") Return EndIf $Proceed = 1 EndFunc Func _Proceed() TrayTip("Autotalker","Started",2) Sleep(5000) While $Proceed = 1 Send(GUICtrlRead($Message) & "{ENTER}") Sleep($Sleep*1000) Send(GUICtrlRead($Message1) & "{ENTER}") Sleep($Sleep*1000) WEnd EndFunc Func Stop() $Proceed = 0 TrayTip("Autotalker","Stopped",2) EndFunc Func Close() Exit EndFunc 00101101011110000101000001101100011011110110100101110100 Link to comment Share on other sites More sharing options...
Tvern Posted September 17, 2010 Share Posted September 17, 2010 (edited) $Sleep is the handle to the control, not the internal value. It's used to point autoit functions to the control you want to use them on. If you want the value of the control $Sleep, use GUICtrlRead() on the handel. It will return the value, which you can then use in your Sleep() Function. To avoid confusion like this it's a good habbit to use descriptive naming, where you can see from the name of a variable what part of the script is relates to, but also what kind of value will be stored in it. (I use $sAdress to store an adress as a string, $aNames to store names as an array and I would use $ctrlSleep to refer to your control, but $iSleep to hold the value (i for integer, or n if it could be other kinds of number).) Edit: General betterness. Now with 100% more coffee in me. Edited September 17, 2010 by Tvern Link to comment Share on other sites More sharing options...
xPloit Posted September 17, 2010 Author Share Posted September 17, 2010 I always forget GUICtrlRead() lol I have no idea why. As soon as someone says it i just think "duh..." haha. Works perfectly! Thanks a lot for all the answers! 00101101011110000101000001101100011011110110100101110100 Link to comment Share on other sites More sharing options...
somdcomputerguy Posted September 17, 2010 Share Posted September 17, 2010 ..and due to a general lack of tutorials.. tutorials abound.. (links in my sig) - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. 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