Jump to content

Stop Script


 Share

Recommended Posts

Um, the goal is that when I press stop on the gui, then the program stops and I am able to change what is in the combo boxes and such and then press start again and it works with new values.

The problem is.. I don't know how to make program stop... I don't know what to put under

Case $msg = $stopbutton

WELL, Here's is my code

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d



;
; ----------------------------------------------------------------------------
;   AutoIt Version: 3.3.6.1
;   Author: Dgameman1
; ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

GUICreate("DG v0.4", 335, 150)

GUISetState(@SW_SHOW)
GUICtrlCreateLabel("Auto Words", 270, 10)

GUICtrlCreateLabel("Word1", 8, 30)
$key1 = GUICtrlCreateCombo("", 40, 27, 45)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "")
$time1 = GUICtrlCreateInput("Delay", 90, 27, 35)


GUICtrlCreateLabel("Word2", 8, 60)
$key2 = GUICtrlCreateCombo("", 40, 54, 45)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "")
$time2 = GUICtrlCreateInput("Delay", 90, 54, 35)


GUICtrlCreateLabel("Word3", 140, 30)
$key3 = GUICtrlCreateCombo("", 172, 27, 45)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "")
$time3 = GUICtrlCreateInput("Delay", 222, 27, 35)


GUICtrlCreateLabel("Word4", 140, 60)
$key4 = GUICtrlCreateCombo("", 172, 54, 45)
GUICtrlSetData(-1, "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z", "")
$time4 = GUICtrlCreateInput("Delay", 222, 54, 35)

$helpbutton = GUICtrlCreateButton("Help", 265, 120, 60)
$startbutton = GUICtrlCreateButton("Start", 265, 35, 60)
$stopbutton = GUICtrlCreateButton("Stop", 265, 62, 60)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $helpbutton
            msgbox(0, "Help", "On your keyboard, press Esc to Exit and Pause to pause")
            
        Case $msg = $stopbutton
                
        Case $msg = $startbutton
            $send1 = GUICtrlRead($key1)
            $sleep1 = GUICtrlRead($time1)
            $send2 = GUICtrlRead($key2)
            $sleep2 = GUICtrlRead($time2)
            $send3 = GUICtrlRead($key3)
            $sleep3 = GUICtrlRead($time3)
            $send4 = GUICtrlRead($key4)
            $sleep4 = GUICtrlRead($time4)

            $TimeStart1 = TimerInit()
            $TimeStart2 = TimerInit()
            $TimeStart3 = TimerInit()
            $TimeStart4 = TimerInit()
            While 1
                $TimeElapsed1 = TimerDiff($TimeStart1)
                $TimeElapsed2 = TimerDiff($TimeStart2)
                $TimeElapsed3 = TimerDiff($TimeStart3)
                $TimeElapsed4 = TimerDiff($TimeStart4)
                If $TimeElapsed1 >= $sleep1 Then
                    ControlSend("[CLASS:Notepad]", "", "", $send1)
                    $TimeStart1 = TimerInit()
                EndIf
                If $TimeElapsed2 >= $sleep2 Then
                    ControlSend("[CLASS:Notepad]", "", "", $send2)
                    $TimeStart2 = TimerInit()
                EndIf
                If $TimeElapsed3 >= $sleep3 Then
                    ControlSend("[CLASS:Notepad]", "", "", $send3)
                    $TimeStart3 = TimerInit()
                EndIf
                If $TimeElapsed4 >= $sleep4 Then
                    ControlSend("[CLASS:Notepad]", "", "", $send4)
                    $TimeStart4 = TimerInit()
                EndIf
            WEnd

        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete()
            Exitloop

    EndSelect

WEnd


;;;;;;;;;;;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func ShowMessage()
    MsgBox(4096, "", "This is a message.")
EndFunc   ;==>ShowMessage
Link to comment
Share on other sites

  • Moderators

Dgameman1,

Please do not bump your posts within 24 hours. :)

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - like this. ;)

Firstly, you need to change your ControlSend lines. At the moment you will only send the letters if the Notepad window is active - as soon as you activate your GUI you pause the sending. Just define the control to which you wish to send the data - which is a pretty essential part of ControlSend if you think about it! :idiot:

So make each line read: ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send#). Just change the # value to match the particular value in each line.

As to resetting the values, you need to look for the "Stop" button being pressed inside the loop that is sending the data - like this:

While 1
    TimeElapsed1 = TimerDiff($TimeStart1)
    $TimeElapsed2 = TimerDiff($TimeStart2)
    $TimeElapsed3 = TimerDiff($TimeStart3)
    $TimeElapsed4 = TimerDiff($TimeStart4)
    If $TimeElapsed1 >= $sleep1 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send1)
        $TimeStart1 = TimerInit()
    EndIf
    If $TimeElapsed2 >= $sleep2 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send2)
        $TimeStart2 = TimerInit()
    EndIf
    If $TimeElapsed3 >= $sleep3 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send3)
        $TimeStart3 = TimerInit()
    EndIf
    If $TimeElapsed4 >= $sleep4 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send4)
        $TimeStart4 = TimerInit()
    EndIf

    If GUIGetMsg() = $stopbutton Then ExitLoop ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

WEnd

That will break out of the loop and you can adjust the various values before hiting "Start" again.

Finally, remove this:

;;;;;;;;;;;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

All it does is keep the script in memory but unresponsive after you have pressed the [X] - which is unlikely to be what you want. :D

I would also strongly suggest that you look into arrays and For...Next loops - you could shorten your code considerably by using them. :D

Please ask if you have any questions. :idiot:

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

Dgameman1,

Please do not bump your posts within 24 hours. :)

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - like this. ;)

Firstly, you need to change your ControlSend lines. At the moment you will only send the letters if the Notepad window is active - as soon as you activate your GUI you pause the sending. Just define the control to which you wish to send the data - which is a pretty essential part of ControlSend if you think about it! :idiot:

So make each line read: ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send#). Just change the # value to match the particular value in each line.

As to resetting the values, you need to look for the "Stop" button being pressed inside the loop that is sending the data - like this:

While 1
    TimeElapsed1 = TimerDiff($TimeStart1)
    $TimeElapsed2 = TimerDiff($TimeStart2)
    $TimeElapsed3 = TimerDiff($TimeStart3)
    $TimeElapsed4 = TimerDiff($TimeStart4)
    If $TimeElapsed1 >= $sleep1 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send1)
        $TimeStart1 = TimerInit()
    EndIf
    If $TimeElapsed2 >= $sleep2 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send2)
        $TimeStart2 = TimerInit()
    EndIf
    If $TimeElapsed3 >= $sleep3 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send3)
        $TimeStart3 = TimerInit()
    EndIf
    If $TimeElapsed4 >= $sleep4 Then
        ControlSend("[CLASS:Notepad]", "", "[CLASS:Edit]", $send4)
        $TimeStart4 = TimerInit()
    EndIf

    If GUIGetMsg() = $stopbutton Then ExitLoop ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

WEnd

That will break out of the loop and you can adjust the various values before hiting "Start" again.

Finally, remove this:

;;;;;;;;;;;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

All it does is keep the script in memory but unresponsive after you have pressed the [X] - which is unlikely to be what you want. :D

I would also strongly suggest that you look into arrays and For...Next loops - you could shorten your code considerably by using them. :D

Please ask if you have any questions. :idiot:

M23

I'm really sorry about the beginning.

Thank you oh so much. You don't understand how thankful I am that you helped me =]

I feel like such an idiot for not figuring that out though =P.

Also, thanks for the other tip. Now my X button works =D

Link to comment
Share on other sites

  • Moderators

Dgameman1,

Glad I could help. :)

Please in future when you reply use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. ;)

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

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