martin Posted May 21, 2008 Share Posted May 21, 2008 (edited) The UDF function SetOnEventA can replace the inbuilt AutoIt functions GuiCtrlSetOnEvent, GuiSetOnEvent, HotKeySet and TraySetOnEvent providing an easy way for an event to call functions with parameters.Example1 - no parameters GuiCtrlCreateButton("Open",20,20,80,22) SetOnEventA(-1,"OpenIt");same as using GuiCtrlSetOnEvent because no parameters listed for the function "OpenIt"Example 2 - 3 parameters Parameters are added to the SetOnEvent function in 2 parts. The first part tells SetOnEvent whether the parameter is a value or a variable, and the second part is the value or variable to be passed to the function. GuiCtrlCreateButton("Open",20,20,80,22) SetOnEventA(-1,"Function1",$paramByVal,$param1,$ParamByVal, $Param2,$ParamByRef, "$VarABC")where $ParamByVal and $ParamByRef are constants defined in the UDF. $ParamByVal means the following parameter for the function is a value. It could be 12 or $SomeVar but whatever it is the value will be used. $ParamByRef means the following parameter is the variable to use. It must be enclosed in quotes as shown above (but with or without the $ prefix). Then, when the function for the event is called the parameter passed will be the value of that variable at the time of the event. So Function1 will appear like this in the script. Func Function1($a,$b)If within the function you need to know the Control which created the event then instead of using @GUI_CtrlId use GetCtrlID() or GetCtrlHandle(). If within the function you need to know the drag ids then use the function EventGetDragIDsExample 3 - Set a Hotkey for Alt k to call the function "StartKerning" with 2 parameters. SetOnEventA("!k","StartKerning",$ParamByVal,26,$ParamByRef,"$margin")Example 4 - Set a Gui event For gui events the first parameter must be passed by Val and the value must either be 0 or the handle of the window the event is for. If you only have one window then the gui handle is not relevant but it must still be the first parameter. SetOnEventA($GUI_EVENT_CLOSE,"AllDone", $paramByVal, $gui,$paramByRef,"$rrdd")Example 5 - Set a Tray menu item event (Version 12 of the UDF or later) $iTrayIt1 =TrayCreateItem("BackGround") TraySetOnEventA(-1,"SetGuiCol", $paramByVal, $iLastGuiCol)Limitations I have only allowed for the function to be called to have up to 5 parameters. (Instructions are in the UDF on how to increase this.) A better solution would be to write your function to have an array as a parameter. If a parameter is a variable then it has to be a Global variable. Although you can have variables passed as parameters, ByRef for a parameter in the function called will have no effect. Here is the udf with an exampleOnEventFunc downloader But the latest udf is attached to post #49 untill I upload it and correct the link.UPDATES: 12th December 2008 UDF changed to a version which doesn't need you to specify the number of parameters passed to the on event function when you call SetOnEventA. It makes things simpler but it isn't compatible with the earlier version. So I've kept the old function SetOnEvent which simply calls the new function without the unnecessary parameter. New scripts can call the new function which is SetOnEventA. 12th Jan 2009. Error in last version corrected. Thanks to FireFox for pointing out something was wrong. 4th Feruary 2009 -V10. Added setting Gui Events, thanks to GaRydelaMer 5th Feb 2009 -V11 corrected error in HotKey event setting in the udf and error in the example. 27th February 2010. Added TraySetOnEventA for Tray menu Items. (Thanks to FireFox) 14th Oct 2011. Corrected forgetting to declare $iParCount in 2 functions. (Thanks to ovideo.) 30th August 2014 Correct overlooking removing a function for an event and allowed for no parameters. (Thanks to PsiLink)mgrefOnEvent Edited August 30, 2014 by martin Messy_Code_Guy and LaoMa 2 Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
nooby Posted May 22, 2008 Share Posted May 22, 2008 I am not at home, so I can't really test this out, however if this does what it's supposed to do, thank you very much! I've always wanted to pass parameters using GUICtrlSetOnEvent, I really hope this works. Thanks for sharing Link to comment Share on other sites More sharing options...
ptrex Posted May 22, 2008 Share Posted May 22, 2008 (edited) @MartinVery nice, save us some time.Suggestion : Maybe remame the Include to OnEventFunc , wich makes more sence (at least to me ?!)And regarding the stored variables. Can be solved using "ByRef" in the Func.SetOnEvent($par0, $Par1, $Par2 = '', $Par3 = '', $Par4 = '', $Par5 = '', $Par6 = '', $par7 = '')Regardsptrex Edited May 22, 2008 by ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Wooltown Posted May 22, 2008 Share Posted May 22, 2008 VERY NICEI will test this, this is a function I have searched for a long time.NICE WORK !!!!! Link to comment Share on other sites More sharing options...
martin Posted May 22, 2008 Author Share Posted May 22, 2008 @MartinVery nice, save us some time.Suggestion : Maybe remame the Include to OnEventFunc , wich makes more sence (at least to me ?!)And regarding the stored variables. Can be solved using "ByRef" in the Func.SetOnEvent($par0, $Par1, $Par2 = '', $Par3 = '', $Par4 = '', $Par5 = '', $Par6 = '', $par7 = '')RegardsptrexCalling the udf OnEventFunc does sound better, I'll change it.Using ByRef hadn't occurred to me, and I'll play with that idea. If it works then it means my understanding of ByRef was wrong.Thanks for your input ptrex. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted May 22, 2008 Author Share Posted May 22, 2008 Using ByRef hadn't occurred to me, and I'll play with that idea. Thanks for your input ptrex.No, I'm sure ByRef doesn't help. Presumably "ByRef $a" uses a pointer to $a, but when you save $a you don't save the pointer but the value. I have often tried to find a way to get pointers to variables but have never succeeded. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ptrex Posted May 22, 2008 Share Posted May 22, 2008 @Martin I realy look into the script deap enough to see if Byref is solving you issue. If I see the time I will try to dig into this a bit deaper. regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
martin Posted May 22, 2008 Author Share Posted May 22, 2008 (edited) @MartinI realy look into the script deap enough to see if Byref is solving you issue.If I see the time I will try to dig into this a bit deaper.regards,ptrexI think I can solve it by copying the way that DllCall is done and specify the parameter types. I can specify whether the parametrs are passed by value or reference like thisConst $paramByVal = 0 Const $ParamByRef = 1 $temp = guiCtrlCreateButton(............ OnEvent($temp,"Functiontocall",$NumOfParams,$paramByRef,"$a",$paramByRef,"$b",$paramByVal,$c,$paramByVal,123)so if you want to pass the parameter by value you specify $paramByVal and use the actual variable or value you want, but if you want the parameter to be a variable then you specify $paramByRef and enclose the variable name in quotes.Then I only have to have a way to store and retrieve that information and I've done it.I'll work on that idea until someone stops me.EDIT: Nobody stopped me. Updated first post to have variables passed. Edited May 22, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted May 30, 2008 Author Share Posted May 30, 2008 (edited) Correction made to the UDF because I assumed that all controls have handles. Some controls, such as menu items, don't have handles. First post updated. Edited May 30, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 30, 2008 Share Posted May 30, 2008 @martin Very good, i like the concept behind the idea! (and the idea itself of course) Thanks for sharing. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
ptrex Posted May 30, 2008 Share Posted May 30, 2008 @all Still wondering why it is not supported natively in au3. Anyone got a clue ? regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
martin Posted May 30, 2008 Author Share Posted May 30, 2008 @martinVery good, i like the concept behind the idea! (and the idea itself of course) Thanks for sharing.Than you MsCreatoR.As you see, you helped me with an important detail. I think the UDF can be useful in scripts like the one gcue is developing. He reads data from an ini file about groups. For each group he creates a button, and for each button he has a context menu. He can end up with several pages of buttons. When a button or context menu item is clicked the function which is called needs a few details about the group. With this udf he can set the information as parameters. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 31, 2008 Share Posted May 31, 2008 @allStill wondering why it is not supported natively in au3. Anyone got a clue ?regardsptrexValik has started a topic about this issue: Callback functions need user-defined parameter Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
martin Posted May 31, 2008 Author Share Posted May 31, 2008 Valik has started a topic about this issue: Callback functions need user-defined parameterAh yes, that made me realize I can use the same function for HotKeys with a small mod, so I have updated the first post so that the SetOnEvent function can be called with either a Control ID or a HotKey sequence. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted January 12, 2009 Author Share Posted January 12, 2009 Error in latest udf corrected. The third line of the function SetOnEvent had a typo. The incorrect line is $parcount = (@numparams - 2)/2 the correct line is $iParCount = (@numparams - 2)/2 The correction has been uploaded. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
rasim Posted January 13, 2009 Share Posted January 13, 2009 @martinVery nice work! Thank you! Link to comment Share on other sites More sharing options...
FireFox Posted January 13, 2009 Share Posted January 13, 2009 @martin Thanks for have fixed error ! Works great now Cheers, FireFox. Link to comment Share on other sites More sharing options...
storme Posted January 17, 2009 Share Posted January 17, 2009 (edited) The concept looks great and I can find a place for it in a new script I'm working on. BUT......... I just tried to download the zip (twice) and it only contains a "short cut" no script. Could you rezip and upload again. Thanks John Morrison Edited January 17, 2009 by storme Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
martin Posted January 17, 2009 Author Share Posted January 17, 2009 (edited) The concept looks great and I can find a place for it in a new script I'm working on.BUT.........I just tried to download the zip (twice) and it only contains a "short cut" no script.Could you rezip and upload again.ThanksJohn MorrisonThat's correct, it contains a shortcut, but you should read the post where the link is Just double click on the shortcut and you will get the udf.EDIT:I have changed the first post and now there is a link to my downloader which I hope will make getting my scripts more straightforward. Edited January 17, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
storme Posted January 18, 2009 Share Posted January 18, 2009 That's correct, it contains a shortcut, but you should read the post where the link is I didn't see anything about clicking on a shortcut... Just double click on the shortcut and you will get the udf.Short cuts can do anything so I am VERY carefull about using them from unverified soruces.EDIT:I have changed the first post and now there is a link to my downloader which I hope will make getting my scripts more straightforward.Yep looks good. I've downloaded it and I'm having a good play with it now.Great work and VERY usefull. I was only thinking about how to do what you have done just before it came to my attention. Thank youJohn Morrison Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E 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