Jump to content

Command for Start Button to run script?


Recommended Posts

I've got a GUI with a start button on it - how do i run the rest of the script when its pressed? Attached is an example and when the start button is pressed the script should start which in this case is a mouse move

#include <GUIConstants.au3>

;GUICreate("my gui", 300, 150) ; will create a dialog box that when displayed is centered
;GUISetState (@SW_SHOW)   ; will display an empty dialog box
;Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("Start",  50, 90, 100)
$Button_2 = GUICtrlCreateButton ( "Stop / Exit",  0, -1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $Button_1
;need command to start script further down
        
Case $msg = $Button_2
    Exit
   
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        EndSelect
    Wend


MouseMove(1200, 400)
Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("my gui", 300, 150) ; will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)    ; will display an empty dialog box
Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)
$Button_1 = GUICtrlCreateButton ("Start",  50, 90, 100)
$Button_2 = GUICtrlCreateButton ( "Stop / Exit",  0, -1)


GuiSetOnEvent($GUI_EVENT_CLOSE,"Quit")
GuICtrlSetOnEvent($Button_2,"Quit")
GuiCtrlSetOnEvent($Button_1,"DoScript")

While 1
    Sleep(100)
WEnd

Func DoScript()
    MouseMove(1200, 400)
EndFunc

Func Quit()
    Exit
EndFunc

IMO it is better to use event mode for your purpose so $Button_2 will work even if your code is executing. Put the rest of your code inside the DoScript() func.

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Excellent Thanks

Just one more thing - how do i integrate my progress bar into the same GUI - when the script runs the progress bar opens in a separate window

#include <GUIConstants.au3>

GUICreate("my gui", 300, 150); will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)   ; will display an empty dialog box
Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)
$Button_1 = GUICtrlCreateButton ("Start",  50, 90, 100)
$Button_2 = GUICtrlCreateButton ( "Stop / Exit",  0, -1)


GuiSetOnEvent($GUI_EVENT_CLOSE,"Quit")
GuICtrlSetOnEvent($Button_2,"Quit")
GuiCtrlSetOnEvent($Button_1,"DoScript")

While 1
    Sleep(100)
WEnd

Func DoScript()
ProgressOn("Progress Bar", "Running","0 percent", 300, 40)
$pbar = 0
ProgressSet( $pbar, $pbar & " percent")
MouseMove(1200, 400)
MouseMove(600, 400)
$pbar = 100
ProgressSet( $pbar, $pbar & " percent")
EndFunc
Func Quit()
    Exit
EndFunc
Link to comment
Share on other sites

Excellent Thanks

Just one more thing - how do i integrate my progress bar into the same GUI - when the script runs the progress bar opens in a separate window

#include <GUIConstants.au3>

GUICreate("my gui", 300, 150); will create a dialog box that when displayed is centered
GUISetState (@SW_SHOW)  ; will display an empty dialog box
Opt("GUICoordMode",2)
Opt("GUIOnEventMode",1)
$Button_1 = GUICtrlCreateButton ("Start",  50, 90, 100)
$Button_2 = GUICtrlCreateButton ( "Stop / Exit",  0, -1)
GuiSetOnEvent($GUI_EVENT_CLOSE,"Quit")
GuICtrlSetOnEvent($Button_2,"Quit")
GuiCtrlSetOnEvent($Button_1,"DoScript")

While 1
    Sleep(100)
WEnd

Func DoScript()
ProgressOn("Progress Bar", "Running","0 percent", 300, 40)
$pbar = 0
ProgressSet( $pbar, $pbar & " percent")
MouseMove(1200, 400)
MouseMove(600, 400)
$pbar = 100
ProgressSet( $pbar, $pbar & " percent")
EndFunc
Func Quit()
    Exit
EndFunc

Look at GuiCtrlCreateProgress(). Then you set the progress with GuiCtrlSetData(). If you use Koda to design the gui its under the "Win32" tab.

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Look at GuiCtrlCreateProgress(). Then you set the progress with GuiCtrlSetData(). If you use Koda to design the gui its under the "Win32" tab.

Spot on :) - managed to recreate it using the GuiCtrlCreateProgress() like you said

Everythings now done - however i've just noticed that the stop/exit button doesnt work when the script is running. It works fine before you click the start button

Have i missed something?

Link to comment
Share on other sites

Spot on :) - managed to recreate it using the GuiCtrlCreateProgress() like you said

Everythings now done - however i've just noticed that the stop/exit button doesnt work when the script is running. It works fine before you click the start button

Have i missed something?

Take a look at "GuiOnEventMode".

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
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...