digitaloutlaw Posted January 1, 2011 Share Posted January 1, 2011 I am new to autoit and have enjoyed playing with it so far have not had many problems. It seems pretty easy even for me with no programming knowledge other than html. So far I have made a gui with some buttons and i have made a script with several different functions now the part I have not been able to figure out is how to make a function start when a button is pressed. Any help with this problem will be appreciated. Link to comment Share on other sites More sharing options...
Mat Posted January 1, 2011 Share Posted January 1, 2011 (edited) Welcome to the forums There are two ways to process clicks and other actions in AutoIt, both are detailed in the GUI reference section of the helpfile. The first is Message-Loop mode: #include <GUIConstantsEx.au3> GUICreate("Testing a message loop") $hMyButton = GUICtrlCreateButton("Click me!", 2, 2, 100, 30) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $hMyButton MyFunction() EndSwitch WEnd Func MyFunction() MsgBox(0, "Test", "Hello World!") EndFunc And the second is OnEvent mode: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) GUICreate("Testing a message loop") GUISetOnEvent($GUI_EVENT_CLOSE, "MyExit") $hMyButton = GUICtrlCreateButton("Click me!", 2, 2, 100, 30) GUICtrlSetOnEvent($hMyButton, "MyFunction") GUISetState() While 1 Sleep(10) WEnd Func MyFunction() MsgBox(0, "Test", "Hello World!") EndFunc Func MyExit() Exit EndFunc Edit: It seems that Melba23 is being a bit slow this morning, it is unusual that I can beat him to the post It must have been a very heavy night last night. Edited January 1, 2011 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 1, 2011 Moderators Share Posted January 1, 2011 digitaloutlaw, Welcome the the AutoIt forum. I have not been able to figure out is how to make a function start when a button is pressedDoes this give you a clue? #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $hButton = GUICtrlCreateButton("Press", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton _Function() EndSwitch WEnd Func _Function() MsgBox(0, "", "Hi there!") EndFunc You might find the excellent tutorials here and here to be of interest if you wish to progress in your AutoIt knowledge. There are even video tutorials on YouTube if you prefer watching to reading. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
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