Jump to content

Multiple functions waiting for user to press a key


youyou
 Share

Recommended Posts

    Hey, I'm pretty new to AutoIt and I've been stuck on this issue for a while now. I've got a GUI with two checkboxes that when checked will wait for the user to enter the specific key before starting their function. Checking one of the boxes at a time works fine, but if they're both checked only the function that comes first in the switch statement will work.

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit
         Case $Checkbox1
            While GUICtrlRead($Checkbox1) = $GUI_CHECKED
               Function1()
            WEnd
         Case $Checkbox2
            While GUICtrlRead($Checkbox2) = $GUI_CHECKED
               Function2()
            WEnd
    EndSwitch
 WEnd

 

Func Function1()
   While _IsPressed(*key*)

   WEnd
EndFunc

Link to comment
Share on other sites

Sorry the rest of my pseudo code got cut off, Here's the entire thing:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
            Exit
         Case $Checkbox1
            While GUICtrlRead($Checkbox1) = $GUI_CHECKED
               Function1()
            WEnd
         Case $Checkbox2
            While GUICtrlRead($Checkbox2) = $GUI_CHECKED
               Function2()
            WEnd
    EndSwitch
 WEnd

 

Func Function1()
   While _IsPressed(*Key*)
*Do stuff*
   WEnd
EndFunc

 

Func Function2()

While_IsPressed(*Other key*)

*Do stuff*

WEnd

EndFunc

Link to comment
Share on other sites

  • Developers
7 minutes ago, youyou said:

While GUICtrlRead($Checkbox1) = $GUI_CHECKED

What is expected from this statement other then you created an endless loop for this one CheckBox.

I guess you are looking for something like this:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    While GUICtrlRead($Checkbox1) = $GUI_CHECKED Or GUICtrlRead($Checkbox2) = $GUI_CHECKED
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
            Function1()
        EndIf
        If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
            Function2()
        EndIf
    WEnd
WEnd

... but this whole script has a gamy ring to it....right?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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