Jump to content
Sign in to follow this  
ronmage

GUI Button help

Recommended Posts

ronmage

Hi, i am using a GUI with a start and stop button. when the start button it hit i want it to run and when you hit stop i would like it to stop. what is going on is that i hit start and i can hit stop and it is real Skippy and not working very well but it will stop at some point. what i am doing it

while 1

$nMsg = GUIGetMsg()

Switch $nMsg

case $Button2

$a=1

EndSwitch

While $a=1

If $nMsg = $button1 then

$a=0

Endif

under this while is about 30 seconds worth the work.

Wend

Wend

Share this post


Link to post
Share on other sites
Melba23

ronmage,

Do you want to interrupt the "30 seconds worth the work" when you press the button or are you happy to wait until it has finished? If you want to interrupt it, does the "work" involve a loop, a series of commands, or is it a single command that takes that time to run? :oops:

The answers to the above will determine how you can best do what you want. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ronmage

when you hit the start button the If statement comes true which is doing work but i am using a few sleep(1000) with in the if statement. i have been running it to problems with the program running faster then the computer so the sleep was the only way i could see to get it to work.

but yes it is a loop that when the if is false then there is a 1 second sleep which is counting up till the if becomes true. looks like this

and yes i was trying to get the stop button to stop in mid way. i know that if it is on a sleep() then it will not stop but that would give a max of 1 second lag.

Just wondering is the answer something to do with a function?

While 1

If $time = 100 then

""the work""

Endif

$Time=$Time+1

Sleep(1000)

Wend

Share this post


Link to post
Share on other sites
Melba23

ronmage,

If you are looking at putting the "work" in a function and there are some places where you can wait and look for an interrruption sign, I suggest you read the Interrupting a running function tutorial in the Wiki - that explains how you can do that in AutoIt. It is a bit advanced in places, but give it a try and ask again if you need to. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ronmage

no the work was not in a function i was wondering if the exit for the loop was going to work with a function. but with that that page you showed me will help me with another problem, sadly not this one

Share this post


Link to post
Share on other sites
Melba23

ronmage,

Unless you show what the "work" consists of it is going to be very difficult to help any more. As I explained above, how we might go about interrupting it depends very much on what exactly is going on during that time. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ronmage

that is a good point. ill post the code. this was me playing around so that code is a mess sorry did not think i was going to be showing anyone

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 318, 146, 1165, 426)
$Button1 = GUICtrlCreateButton("Start", 24, 80, 97, 33)
$Button2 = GUICtrlCreateButton("Stop", 184, 80, 97, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
HotKeySet("+{ESC}", "_Exit")
MsgBox(0, "Info", "To Exit the program Hit Shift + Esc")
$a=120
$b=900
$c=0
$d=0
$e=0
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $e=1
EndSwitch
While $e=1
  $nMsg = GUIGetMsg()
  If $nMsg = $Button2 Then
   $e=0
   Exit
  EndIf
If $a > 117 Then
  Beep()
  EndIf
While $a >= 120
  If $d=0 Then
   MouseClick("left", -616, 333,3,10)
   Sleep(200)
   MouseClick("left", -69, 89,2,5)
   $d=1
  EndIf
   Sleep(300)
   MouseClick("left", -977, $b,1,0)
   $b=$b-10
    If $b <= 600 Then
     $b = 900
     $d=0
    $c=$c+1
    Sleep(100)
    EndIf

   If $c = 2 Then
    Sleep(1000)
    MouseClick("left", -1069, 594,3,10)
    Sleep(1000)
    MouseClick("left", -266, 412,3,10)
    Sleep(1000)
    MouseClick("left", -1027, 677)
    Sleep(1000)
    MouseClick("left", -266, 412,3,10)
    $b=870
    $a=0
    $c=0
   EndIf
  WEnd
Sleep(1000)
$a=$a+1
WEnd
WEnd

Func _Exit()
MsgBox(0, "Goodbye", "I'm exiting now")
Exit
EndFunc   ;==>_Exit

what it is doing is when you hit the start button it works in this case it is moving the mouse so i cant test the stopping mid run. but what it is doing is when it is done running there is a gap where it is counting up 2 min, in that time i want to hit stop and have it stop right there you have to spam click it a bit to get it to stop.

the other way to do it would to when you click it get the button to change somehow showing that it was pressed and will close soon

Share this post


Link to post
Share on other sites
Melba23

ronmage,

You have plenty of places to look for the "Stop button. :oops:

Here is something that should work - note I have replaced all the MouseClicks with ConsoleWrites so you can see what is going on:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("+{ESC}", "_Exit")

$Form1 = GUICreate("Form1", 318, 146, 1165, 426)
$Button1 = GUICtrlCreateButton("Start", 24, 80, 97, 33)
$Button2 = GUICtrlCreateButton("Stop", 184, 80, 97, 33)
GUISetState(@SW_SHOW)

MsgBox(0, "Info", "To Exit the program Hit Shift + Esc")

$a = 120
$b = 900
$c = 0
$d = 0
$e = 0

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $e = 1
    EndSwitch

    While $e = 1

        If $a > 117 Then
            Beep()
        EndIf
        While $a >= 120
            If $d = 0 Then
                ; MouseClick("left", -616, 333, 3, 10)
                ConsoleWrite("Click" & @CRLF)
                _Wait(200)
                ; MouseClick("left", -69, 89, 2, 5)
                ConsoleWrite("Click" & @CRLF)
                $d = 1
            EndIf
            _Wait(300)
            ; MouseClick("left", -977, $b, 1, 0)
            ConsoleWrite("Click" & @CRLF)
            $b = $b - 10
            If $b <= 600 Then
                $b = 900
                $d = 0
                $c = $c + 1
                _Wait(100)
            EndIf

            If $c = 2 Then
                _Wait(1000)
                ; MouseClick("left", -1069, 594, 3, 10)
                ConsoleWrite("Click" & @CRLF)
                _Wait(1000)
                ; MouseClick("left", -266, 412, 3, 10)
                ConsoleWrite("Click" & @CRLF)
                _Wait(1000)
                ; MouseClick("left", -1027, 677)
                ConsoleWrite("Click" & @CRLF)
                _Wait(1000)
                ; MouseClick("left", -266, 412, 3, 10)
                ConsoleWrite("Click" & @CRLF)
                $b = 870
                $a = 0
                $c = 0
            EndIf
        WEnd
        _Wait(1000)
        $a = $a + 1
    WEnd
WEnd

Func _Wait($iDelay)

    $iBegin = TimerInit()
    Do
        Switch GUIGetMsg()
            Case $Button2
                ConsoleWrite("Exiting" & @CRLF)
                Exit
        EndSwitch
    Until TimerDiff($iBegin) > $iDelay

EndFunc

Func _Exit()
    MsgBox(0, "Goodbye", "I'm exiting now")
    Exit
EndFunc   ;==>_Exit

All clear? Please ask if not. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ronmage

wow that works WAY better. never used TimerInit.

thank you so much that is great ty

Share this post


Link to post
Share on other sites
ProfessorBean

nevermind, i fixed it, please remove this.

Edited by ProfessorBean
Code removed.

Share this post


Link to post
Share on other sites
Valik

HI i have a gui and a list of hotkey sets, how do i make the two work to gather?

this is my GUI

<Removed>

this is my hotkeys

<Removed>

now the hotkeys work fine and the gui works fine but when i try and merge the two it doesn't work.... help.

You are hijacking a dead thread to ask for help with something against the rules (game automation). That's not exactly the best course of action. Before you post again I suggest you locate your brain, insert it back into your head and then use it to read (and comprehend!) the forum rules.

Share this post


Link to post
Share on other sites
ProfessorBean

nevermind, i fixed it, please remove this.

Edited by ProfessorBean

Share this post


Link to post
Share on other sites
Valik

I see that you were unable to locate your brain. That is unfortunate.

Share this post


Link to post
Share on other sites
ProfessorBean

nevermind, i fixed it, please remove this.

Edited by ProfessorBean

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  

×