iMacg3 Posted September 3, 2018 Posted September 3, 2018 Hi, New to the forum and AutoIt. Still learning the basics of how to code in AutoIt. Just a question that should be easy for all of you experts to answer. After creating a button in a GUI, what would be the best way to make the action of the user clicking the button run another AutoIt script? Thanks.
FrancescoDiMuro Posted September 4, 2018 Posted September 4, 2018 (edited) Hi @iMacg3, and welcome to the AutoIt Forum Mainly, there are two ways to make an action when pressing a button. The first, is by using an infinite While loop, in which there's a function called GUIGetMsg(), which continuously sees if there are new "messages", like a button press, the close event of the GUI, and so on. The structure what I've described has this form: Local $idMsg = 0 While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $idButton ; Make actions when $idButton has been pressed Case $GUI_EVENT_CLOSE ; Exit the script, since the "X" button of the GUI has been pressed Exit EndSwitch WEnd The second one, is by using the option "OnEventMode = 1", which means that, the script, will not continuously sees if there are new messages, but will process them and take actions only when the event(s) effectively occur(s). The structure of what I've described has this form: Global $GUI = GUICreate() GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") Global $idButton = GUICtrlCreateButton(...) GUICtrlSetOnEvent(-1, "idButton_Click") GUISetState($hGUI, @SW_SHOW) While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func idButton_Click() ; The button has been pressed EndFunc You can find more about GUIGetMsg() and the Option OnEventMode in the Help file P.S.: If you want to make a GUI without manually calculating the position of the controls, you can use Koda Form Designer Edited September 4, 2018 by FrancescoDiMuro caramen 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
iMacg3 Posted September 6, 2018 Author Posted September 6, 2018 Thanks for your help. I will read the tutorials in the help file about what you mentioned above.
markyrocks Posted September 6, 2018 Posted September 6, 2018 (edited) You could #Include "YourOtherScript.au3" (this assumes that it resides in the main script directory. You can also add a path) And just call specific functions from that script from your main script when button is pressed. Edited September 6, 2018 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning"
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now