Jump to content

quick question about loops and GUI buttons


Stephen89
 Share

Recommended Posts

ok here's my problem. i have a simple GUI which calls different functions for each button.

so example button "A" will call a()

and button "B" will call b()

button "C" will pause the script

button "D" will exit

cant make it work.. whenever i press button "A" it waits for a() to finish first so that the other buttons can function.. i want the buttons to be in the top priority so eventhough function a() is not yet finish, when i click button "C" the script should pause.

i don't know what im doing wrong.. :graduated:

so i will put my GUI SCRIPT... functions not included yet.. that works just fine but with functions that have while statements inside or do until statements, i can't make the pause or exit button to work... after running the function

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Users\Brix\Desktop\koda\Forms\Form1.kxf

$Form1 = GUICreate("888", 151, 224, 192, 124)

$script = 0

$y = 0

$x = TimerInit()

$1 = 0

$2 = 0

$3 = 0

$Button1 = GUICtrlCreateButton("Start", 45, 128, 57, 25)

$Button2 = GUICtrlCreateButton("Start", 45, 168, 57, 25)

$Button3 = GUICtrlCreateButton("Pause", 45, 168, 57, 25)

GUICtrlSetState(-1, $GUI_HIDE)

$Label1 = GUICtrlCreateLabel("A", 8, 112, 26, 17)

$Label2 = GUICtrlCreateLabel("B", 8, 160, 25, 17)

$Label6 = GUICtrlCreateLabel("A", 8, 160, 25, 17)

GUICtrlSetState(-1, $GUI_HIDE)

$Label3 = GUICtrlCreateLabel("THE SCRIPT IS RUNNING", 8, 32, 136, 57)

GUICtrlSetState(-1, $GUI_HIDE)

GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")

GUICtrlSetColor(-1, 0xFF0000)

$Label4 = GUICtrlCreateLabel("THE SCRIPT IS PAUSED", 8, 32, 136, 57)

GUICtrlSetState(-1, $GUI_HIDE)

GUICtrlSetFont(-1, 6, 800, 0, "MS Sans Serif")

GUICtrlSetColor(-1, 0xFF0000)

$Label5 = GUICtrlCreateLabel("Hotkeys:" & @CRLF & "'PAUSE BREAK' to toggle PAUSE / RESUME" & @CRLF & "'DEL' to see INFO" & @CRLF & "'END' to exit the program", 8, 32, 150, 70)

GUICtrlSetFont(-1, 5, 500, 0, "MS Sans Serif")

GUICtrlSetColor(-1, 0xFF0000)

$Label7 = GUICtrlCreateLabel("", 8, 0, 150, 30)

GUICtrlSetState(-1, $GUI_HIDE)

$Pic1 = GUICtrlCreatePic("C:\Users\Brix\Desktop\th_smiley-face-wallpaper-008.jpg", 24, 75, 97, 65, BitOR($GUI_SS_DEFAULT_PIC,$SS_NOPREFIX,$SS_CENTERIMAGE,$SS_RIGHTJUST,$SS_SUNKEN))

GUICtrlSetState(-1, $GUI_HIDE)

$Pic2 = GUICtrlCreatePic("C:\Users\Brix\Desktop\8ccba62f3d8102dc.jpg", 104, 0, 49, 41, BitOR($GUI_SS_DEFAULT_PIC,$SS_NOPREFIX,$SS_CENTERIMAGE,$SS_RIGHTJUST))

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$y = TimerDiff($x)

$y = $y * .001

$y = Round($y, 0)

If $y < 60 And $2 < 60 Then

$3 = $y

GUICtrlSetData($Label7,"UPTIME " & @crlf & $1 & " hours" & $2 & " mins" & $3 & " sec")

ElseIf $y < 60 And $2 > 59.99 Then

$1 = $1 + $1

$2 = 0

GUICtrlSetData($Label7,"uptime " & $1 & " hours" & $2 & " mins" & $3 & " sec")

Else

$2 = $2 + 1

$x = TimerInit()

EndIf

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

$x = TimerInit()

$1 = 0

$2 = 0

$3 = 0

GUICtrlSetState($button1, $GUI_HIDE)

GUICtrlSetState($button2, $GUI_HIDE)

GUICtrlSetState($label1, $GUI_HIDE)

GUICtrlSetState($label2, $GUI_HIDE)

GUICtrlSetState($label6, $GUI_SHOW)

GUICtrlSetState($button3, $GUI_SHOW)

GUICtrlSetState($pic1, $GUI_SHOW)

GUICtrlSetState($pic2, $GUI_HIDE)

GUICtrlSetState($label5, $GUI_HIDE)

GUICtrlSetState($label7, $GUI_SHOW)

GUICtrlSetState($label3, $GUI_SHOW)

$Script=1

Case $Button2

GUICtrlSetState($button1, $GUI_HIDE)

GUICtrlSetState($label1, $GUI_HIDE)

GUICtrlSetState($pic2, $GUI_HIDE)

If $Script=0 Then

GUICtrlSetData($Button2,"Pause")

$Script=1

GUICtrlSetState($label4, $GUI_HIDE)

GUICtrlSetState($label5, $GUI_HIDE)

GUICtrlSetState($label3, $GUI_SHOW)

GUICtrlSetState($pic1, $GUI_SHOW)

Else

GUICtrlSetData($Button2,"Start")

$Script=0

GUICtrlSetState($label3, $GUI_HIDE)

GUICtrlSetState($label4, $GUI_SHOW)

EndIf

Case $Button3

If $Script=0 Then

GUICtrlSetData($Button3,"Pause")

$Script=1

GUICtrlSetState($label4, $GUI_HIDE)

GUICtrlSetState($label5, $GUI_HIDE)

GUICtrlSetState($label3, $GUI_SHOW)

GUICtrlSetState($pic1, $GUI_SHOW)

Else

GUICtrlSetData($Button3,"Start")

$Script=0

GUICtrlSetState($label3, $GUI_HIDE)

GUICtrlSetState($label4, $GUI_SHOW)

EndIf

EndSwitch

WEnd

Link to comment
Share on other sites

Check out this link for how to interrupt a function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Check out this link for how to interrupt a function.

thanks alot been tryin to make it work but still got some problem...

below is the function i want to interrupt

i followed the tutorial in the link you gave me but just when i press the hotkey,accelerator or the button, it wont do the function asap. it still waits for this function to finish before interrupted

Func a() ;

$fInterrupt = 0

While 1

$coord = PixelSearch( 168, 644, 191, 670, 0xAA3539, 2 ) ; pixel detect login screen

If Not @error Then

ConsoleWrite("login" & @CRLF)

MouseClick("Left",496,260,1)

sleep(80)

MouseClick("Left",498,485,2)

sleep(80)

ControlSend($prog,'','',$message)

Sleep(100)

MouseClick("Left",453,568,1)

Sleep(200)

ElseIf @error Then

ConsoleWrite("error" & @CRLF)

Sleep(500)

EndIf

If $fInterrupt <> 0 Then

; The flag was set

Switch $fInterrupt

Case 1

ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF)

Case 2

ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF)

Case 3

ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF)

EndSwitch

Return

EndIf

Sleep(100)

WEnd

EndFunc

Edited by Stephen89
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...