Jump to content

Trouble understanding GUI while loop and order it fires functions


Recommended Posts

I have a script that runs just fine, below is an example of what I am doing, When I run this code, each function waits until the left mouse button is clicked and then will go to the next function:

Start()

Func Start()
    Function1()
    Function2()
    Function3()
EndFunc

Func Function1()
    Local $hDLL = DllOpen("user32.dll")
    While 1
      If _IsPressed("01", $hDLL) Then
        ExitLoop
      EndIf
    WEnd
EndFunc

Func Function2()
    Local $hDLL = DllOpen("user32.dll")
    While 1
      If _IsPressed("01", $hDLL) Then
        ExitLoop
      EndIf
    WEnd
EndFunc

Func Function3()
    Local $hDLL = DllOpen("user32.dll")
    While 1
      If _IsPressed("01", $hDLL) Then
        ExitLoop
      EndIf
    WEnd
EndFunc

But when I add a GUI window and start this script with a button, it fires all at once and does not wait.

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartButton
            Start()
        Case $StopButton
            Exit
    EndSwitch
WEnd

Func Start()
    Function1()
    Function2()
    Function3()
EndFunc

Func Function1()
    Local $hDLL = DllOpen("user32.dll")
    While 1
      If _IsPressed("01", $hDLL) Then
        ExitLoop
      EndIf
    WEnd
EndFunc

Func Function2()
    Local $hDLL = DllOpen("user32.dll")
    While 1
      If _IsPressed("01", $hDLL) Then
        ExitLoop
      EndIf
    WEnd
EndFunc

Func Function3()
    Local $hDLL = DllOpen("user32.dll")
    While 1
      If _IsPressed("01", $hDLL) Then
        ExitLoop
      EndIf
    WEnd
EndFunc

How can I get the GUI to act the same way as just running it on the page?

Thanks!

Link to post
Share on other sites

You can not have a loop inside a GUI loop.  You will have to gather everything inside a single loop.

OR use GUI event instead of GUI loop.

Link to post
Share on other sites
10 hours ago, Zathus said:

How can I get the GUI to act the same way as just running it on the page?

try this:

Func Start()
    Function1()
    Sleep(50)
    Function2()
    Sleep(50)
    Function3()
EndFunc

reason is because _IsPressed doesn’t actually detect mouse clicks, it just says whether the mouse button is down at any given instant.  most likely, it’s still returning true when it gets to function 2.  Why it doesn’t do this in your original script, I’m not sure.  Maybe you clicked quicker then...

Code hard, but don’t hard code...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...