Jump to content

Pause until button is clicked...


 Share

Recommended Posts

  • Moderators

Guys,

Is there a way you can pause a script until a button is pressed on the gui?

Cheers,

Michael

Opt('GUISetOnEventMode', x)

While 1
    Sleep(1000)
WEnd

;Rest of functions
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

That code SmOke_N gave you confused me, so it case it did you too, here is (to my understanding) the kinda more standard way of doing it

$MainWinID=GuiCreate("Your GUI Window") ;Creates your Window and stores its ID in the variable $MainWinID

$Your_Buttons_Control_ID=GUICtrlCreateButton("Your Button", 0, 0) ;Creates your button and stores its ID in the variable

GUISetState(@SW_SHOW) ;shows the GUI

while 1 ;set a never ending loop
    $Event=GuiGetMsg() ;this functions checks to see if the user has interacted with the GUI, and if so stores which control was interacted with
    select
        case $Event=$GUI_EVENT_CLOSE ;If the user clicked  the exit button, do the following
            exitloop
        case $Event=$Your_Buttons_Control_ID ;If the user clicked your button, do the following
            ;Your code here
    EndSelect
WEnd

Exit

;any Functions you have should be defined here

[sup]Psibernetic[/sup]My Creations:X-HideSecuracy

Link to comment
Share on other sites

  • Moderators

That code SmOke_N gave you confused me, so it case it did you too, here is (to my understanding) the kinda more standard way of doing it

Shouldn't confuse you if you look at the functions for GUISetOnEvent*
Opt('GUIOnEventMode', 1)
$Main = GUICreate('Example:', 100, 100)
$Button = GUICtrlCreateButton('Click Me', 0, 0, 100, 100)
GUISetOnEvent(-3, '_ByeBye');Set $GUI_EVENT_CLOSE function
GUICtrlSetOnEvent($Button, '_EventHandler');Set Control to an Event Handler

GUISetState()

While 1
    ;Lets Just Sleep As Long As Allowed, Until You Need Me
    Sleep(0x7FFFFFFF)
WEnd

Func _EventHandler()
    Switch @GUI_CtrlId
        Case $Button
            _CallSomeFunction()
    EndSwitch
EndFunc

Func _CallSomeFunction()
    Return MsgBox(64, 'Found', 'Ok, you called me, now what do you want?')
EndFunc

Func _ByeBye()
    Exit 1
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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