Sign in to follow this  
Followers 0
DemonAngel

Stop Button, How To

16 posts in this topic

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.

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

While 1

Sleep(10)

WEnd

@DemonAngel,

Your code worked for me with that one addition.

There are errors reported in SciTE...

hang on...

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

herewasplato, I added the sleep(10) with no affect to the script. Where did you add it?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

herewasplato, I added the sleep(10) with no affect to the script. Where did you add it?

GuiSetState()

While 1

Sleep(10)

WEnd

Exit

Look 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]

Share this post


Link to post
Share on other sites

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.

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

:)

Share this post


Link to post
Share on other sites

Hi greenmachine

I had the script use GuiGetMsg when I started. Had the same problem so I decided to goto onevent instead.

Share this post


Link to post
Share on other sites

#12 ·  Posted (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\beta

c:\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: 0

It 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 top

Global $Input, $Delay, $Stop, $start

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

#14 ·  Posted (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, $start

will make it work

edit - 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 by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Score one for me:

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

Share this post


Link to post
Share on other sites

Yip , Score one for you :)

Thanx for that

Share this post


Link to post
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
Sign in to follow this  
Followers 0