Jump to content
youyou

Multiple functions waiting for user to press a key

Recommended Posts

youyou

    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

Share this post


Link to post
Share on other sites
youyou

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

Share this post


Link to post
Share on other sites
Jos
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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
youyou

It works now, thanks so much dude! I feel so dumb now, haha.

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.