Jump to content



Photo

GUI Button help


  • Please log in to reply
13 replies to this topic

#1 ronmage

ronmage

    Seeker

  • Active Members
  • 20 posts

Posted 02 March 2012 - 04:30 AM

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







#2 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,398 posts

Posted 02 March 2012 - 08:36 AM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#3 ronmage

ronmage

    Seeker

  • Active Members
  • 20 posts

Posted 02 March 2012 - 06:00 PM

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

#4 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,398 posts

Posted 02 March 2012 - 06:04 PM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#5 ronmage

ronmage

    Seeker

  • Active Members
  • 20 posts

Posted 03 March 2012 - 02:15 AM

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

#6 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,398 posts

Posted 03 March 2012 - 08:42 AM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#7 ronmage

ronmage

    Seeker

  • Active Members
  • 20 posts

Posted 03 March 2012 - 06:34 PM

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
Plain Text         
#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

#8 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,398 posts

Posted 03 March 2012 - 06:44 PM

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:
AutoIt         
#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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#9 ronmage

ronmage

    Seeker

  • Active Members
  • 20 posts

Posted 04 March 2012 - 01:42 AM

wow that works WAY better. never used TimerInit.

thank you so much that is great ty

#10 ProfessorBean

ProfessorBean

    Seeker

  • Active Members
  • 6 posts

Posted 14 March 2012 - 12:36 AM

nevermind, i fixed it, please remove this.

Edited by ProfessorBean, 14 March 2012 - 03:47 AM.
Code removed.


#11 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 14 March 2012 - 02:01 AM

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.

#12 ProfessorBean

ProfessorBean

    Seeker

  • Active Members
  • 6 posts

Posted 14 March 2012 - 02:21 AM

nevermind, i fixed it, please remove this.

Edited by ProfessorBean, 14 March 2012 - 03:48 AM.


#13 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 14 March 2012 - 02:29 AM

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

#14 ProfessorBean

ProfessorBean

    Seeker

  • Active Members
  • 6 posts

Posted 14 March 2012 - 02:57 AM

nevermind, i fixed it, please remove this.

Edited by ProfessorBean, 14 March 2012 - 03:48 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users