DemonAngel Posted March 27, 2006 Share Posted March 27, 2006 I am trying to get my stop button to work. It does not want to function because of the script is busy with another function. Any Idees will be appreciated. expandcollapse popup; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.0 ; Author: A.N.Other <myemail@nowhere.com> ; ; Script Function: ; Template AutoIt script. ; ; ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) Global $Time = "" Global $mousex = 0 Global $mousey = 0 Global $Delay ;Global $start = "" GuiCreate("Clicker", 140, 30);,(@DesktopWidth-140)/2, (@DesktopHeight-40)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Record = GuiCtrlCreateButton("Record Location", 0, 0, 100, 30) $Timer = GuiCtrlCreateLabel($Time, 110, 7, 40, 20) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlSetOnEvent($Record, "RecordMouse") GuiSetState() While 1 WEnd Exit Func StartClick() $Delay = GUICtrlRead($Input) If $Delay = "" then Return GUICtrlDelete($start) $Stop = GuiCtrlCreateButton("Stop", 0, 0, 60, 30) While 1 MouseClick("left",$mousex,$mousey) updatetimer($Delay) WEnd EndFunc Func RecordMouse() updatetimer(5) GUICtrlDelete($Record) $mouse = MouseGetPos() $mousex = $mouse[0] $mousey = $mouse[1] Global $Start = GuiCtrlCreateButton("Start", 0, 0, 60, 30) GUICtrlSetOnEvent($Start, "StartClick") Sleep(100) Global $Input = GUICtrlCreateInput("",60,5,40,20) EndFunc Func CLOSEClicked() Exit EndFunc Func updatetimer($Time) for $counter = $Time to 1 Step -1 GUICtrlSetData($Timer,$counter) Sleep(1000) Next GUICtrlSetData($Timer,"") Return EndFunc Link to comment Share on other sites More sharing options...
Nuffilein805 Posted March 27, 2006 Share Posted March 27, 2006 how about hotkeyset? hotkeyset("{esc}", "stop") func stop() exit endfunc my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
DemonAngel Posted March 27, 2006 Author Share Posted March 27, 2006 Was kinda hoping to get the stop button to work. I dont want the stop button to exit the entire script, just the click fuction that it would be busy with. Thanx for the reply though. Link to comment Share on other sites More sharing options...
herewasplato Posted March 27, 2006 Share Posted March 27, 2006 (edited) While 1Sleep(10)WEnd@DemonAngel,Your code worked for me with that one addition.There are errors reported in SciTE... hang on... Edited March 27, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Nuffilein805 Posted March 27, 2006 Share Posted March 27, 2006 hotkeyset("{esc}", "stop") func stop() while 1 sleep (10) wend endfunc hope this is what you want my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
DemonAngel Posted March 27, 2006 Author Share Posted March 27, 2006 herewasplato, I added the sleep(10) with no affect to the script. Where did you add it? Link to comment Share on other sites More sharing options...
Nuffilein805 Posted March 27, 2006 Share Posted March 27, 2006 the sleep (10) does only reduce the cpu-load, so you don't have to do it in there if you have a high-end-pc my little chatmy little encryption toolmy little hidermy unsafe clickbot Link to comment Share on other sites More sharing options...
greenmachine Posted March 27, 2006 Share Posted March 27, 2006 Well what I noticed is that you don't have an event for your stop button. However, if you create an OnEvent for the stop button inside the loop, it will never work (for whatever reason, Gui OnEvents created inside a function aren't registered). So... try changing to GuiGetMsg, and see if that gets you anywhere. Link to comment Share on other sites More sharing options...
herewasplato Posted March 27, 2006 Share Posted March 27, 2006 herewasplato, I added the sleep(10) with no affect to the script. Where did you add it?GuiSetState()While 1Sleep(10)WEndExitLook at SciTE's output - there are problems with your variables... global/local...I just thought that it worked for me - I apparently do not understand what it is supposed to do to make that judgment. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
DemonAngel Posted March 27, 2006 Author Share Posted March 27, 2006 The script works in the following way. 1. It records the location of your mouse. (Gives you 5 secs to get the mouse to the correct spot) 2. When you click start it clicks a single mouse click at certain intervals. (whatever number of seconds you type into the text box) After you click start, the start key becomes a stop key. I want the stop key to just exit the function, unfortunatly the stop key wont register while the click loop is running. expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) hotkeyset("{esc}", "CLOSEClicked") Global $Time = "" Global $mousex = 0 Global $mousey = 0 Global $Delay ;Global $start = "" GuiCreate("Clicker", 140, 30);,(@DesktopWidth-140)/2, (@DesktopHeight-40)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Record = GuiCtrlCreateButton("Record Location", 0, 0, 100, 30) $Timer = GuiCtrlCreateLabel($Time, 110, 7, 40, 20) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlSetOnEvent($Record, "RecordMouse") GuiSetState() While 1 Sleep(10) WEnd Exit Func StartClick() $Delay = GUICtrlRead($Input) If $Delay = "" then Return GUICtrlDelete($start) $Stop = GuiCtrlCreateButton("Stop", 0, 0, 60, 30) While 1 MouseClick("left",$mousex,$mousey) updatetimer($Delay) WEnd EndFunc Func RecordMouse() updatetimer(5) GUICtrlDelete($Record) $mouse = MouseGetPos() $mousex = $mouse[0] $mousey = $mouse[1] Global $Start = GuiCtrlCreateButton("Start", 0, 0, 60, 30) GUICtrlSetOnEvent($Start, "StartClick") Sleep(100) Global $Input = GUICtrlCreateInput("",60,5,40,20) EndFunc Func CLOSEClicked() Exit EndFunc Func updatetimer($Time) for $counter = $Time to 1 Step -1 GUICtrlSetData($Timer,$counter) Sleep(1000) Next GUICtrlSetData($Timer,"") Return EndFunc Please give it a try and let me know how you think I can solve this. Link to comment Share on other sites More sharing options...
DemonAngel Posted March 27, 2006 Author Share Posted March 27, 2006 Hi greenmachine I had the script use GuiGetMsg when I started. Had the same problem so I decided to goto onevent instead. Link to comment Share on other sites More sharing options...
herewasplato Posted March 27, 2006 Share Posted March 27, 2006 (edited) Just running a syntax check on your last posted code gets you:>Running AU3Check (1.54.1.0) params: from:C:\Program Files\AutoIt3\betac:\Temp\SciTE-temp.au3(30,32) : WARNING: $Input: possibly used before declaration. $Delay = GUICtrlRead($Input)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^c:\Temp\SciTE-temp.au3(32,25) : WARNING: $start: possibly used before declaration. GUICtrlDelete($start)~~~~~~~~~~~~~~~~~~~~~~~~^c:\Temp\SciTE-temp.au3 - 0 error(s), 2 warning(s)->AU3Check ended.rc:1>Exit code: 0 Time: 0It is not a good idea to rely on a stop button - what if some idiot (like me) does not put a time into the input box - your little clicker script is fun to kill. Fortunately, I know that I'm an idiot at times and I have an OS shortcut key that kills AutoIt scripts.add this near the topGlobal $Input, $Delay, $Stop, $start Edited March 27, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
DemonAngel Posted March 27, 2006 Author Share Posted March 27, 2006 Good point. I will script a section telling the script not to run if the delay is less then 5 secs. The "esc" button should exit the script in the meen time. PS, Those warnings dont seem like a problem to me? Link to comment Share on other sites More sharing options...
herewasplato Posted March 27, 2006 Share Posted March 27, 2006 (edited) Good point. I will script a section telling the script not to run if the delay is less then 5 secs. The "esc" button should exit the script in the meen time.PS, Those warnings dont seem like a problem to me?Global $Input, $Delay, $Stop, $startwill make it workedit - well at least the stop button shows now... not sure that it stops as you want it to -I must still not understand - but I do understand that I should be in bed.........later Edited March 27, 2006 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
greenmachine Posted March 27, 2006 Share Posted March 27, 2006 Score one for me: expandcollapse popup#include <GuiConstants.au3> Global $Time = "" Global $mousex = 0 Global $mousey = 0 Global $Delay Global $go = 1 Global $start Global $Input, $Stop GuiCreate("Clicker", 140, 30);,(@DesktopWidth-140)/2, (@DesktopHeight-40)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Record = GuiCtrlCreateButton("Record Location", 0, 0, 100, 30) $Timer = GuiCtrlCreateLabel($Time, 110, 7, 40, 20) GuiSetState() While 1 $msg = GUIGetMsg () Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Record RecordMouse() Case $msg = $start StartClick() EndSelect If GUICtrlRead ($timer) <> "" Then GUICtrlSetData ($timer, "") EndIf WEnd Exit Func StartClick() $Delay = GUICtrlRead($Input) If $Delay = "" then Return GUICtrlDelete($start) $Stop = GuiCtrlCreateButton("Stop", 0, 0, 60, 30) While 1 $timers = TimerInit () While TimerDiff ($Timers)/1000 < $Delay $msg = GUIGetMsg () If $msg = $GUI_EVENT_CLOSE Then Exit ElseIf $msg = $Stop Then Return EndIf If $Delay - Int (TimerDiff($timers)/1000) <> GUICtrlRead ($timer) Then GUICtrlSetData ($Timer, $Delay - Int (TimerDiff($timers)/1000)) EndIf WEnd GUICtrlSetData ($timer, "") MouseClick("left",$mousex,$mousey) WEnd EndFunc Func RecordMouse() updatetimer(5) GUICtrlDelete($Record) $mouse = MouseGetPos() $mousex = $mouse[0] $mousey = $mouse[1] $Start = GuiCtrlCreateButton("Start", 0, 0, 60, 30) Sleep(100) $Input = GUICtrlCreateInput("",60,5,40,20) EndFunc Func CLOSEClicked() Exit EndFunc Func updatetimer($Time) for $counter = $Time to 1 Step -1 GUICtrlSetData($Timer,$counter) Sleep(1000) Next GUICtrlSetData($Timer,"") Return EndFunc Had to add some genius ideas in there for the timers and stuff.... Link to comment Share on other sites More sharing options...
DemonAngel Posted March 27, 2006 Author Share Posted March 27, 2006 Yip , Score one for you Thanx for that 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