minxomat Posted September 20, 2015 Share Posted September 20, 2015 IntroductionThe recently introduced feature of passing function pointers as arguments makes it possible, with the help of this UDF to create abriatary events with arguments. Here is a very simple example of a single-execution event:#include "GlobalEvents.au3" _GlobalEvents_Create("@SEC = 30", Test1) While Sleep(30) WEnd Func Test1() MsgBox(0, "Test", "@SEC equals 30!") EndFuncThis event will be triggered once, when @SEC is 30 and then die. FeaturesCreate how many events you want.An event can be created on every possible single-line AutoIt expression.You can pass an array of arguments to the event handler.There are two types of events: Single-execution (those are triggered once, then die - though you can reset them) and Looping, where the event triggers every time it evaluates true.You can pause and restart the evaluation of all events.You can set the delay between evaluations (standard is 333ms).You can destroy events. (The global event pool has an initial size of 1024 to prevent ReDim-ing. Destroying old events further prevents ReDim-ing.)It doesn't matter if your script operates in OnEvent or Message mode. You can use everything as usual (yes, even OnEvents and Adlib). Examples1. Single-Execution (+ with arguments)#include "GlobalEvents.au3" Local $hGUI, $hLabel, $hInput, $sPassword = "1234" ; Trigger Test1 when $hGUI receives a value. And trigger only once. _GlobalEvents_Create("$hGUI", Test1) ; Trigger Test2 when the right password was entered, exit the script from the event. ; Pass some arguments :) _GlobalEvents_Create("GuiCtrlRead($hInput) == $sPassword", Test2, 0, MouseGetPos()) $hGUI = GUICreate("", 175, 50) $hLabel = GUICtrlCreateLabel("Enter your password (1234)!", 0, 5, 175, 15, 1) $hInput = GUICtrlCreateInput("", 5, 25, 165, 20, 1) GUISetState() While GUIGetMsg() <> -3 WEnd ; Event handler 1 Func Test1() MsgBox(0, "Event Test1", "GUI was created!") EndFunc ; Event handler 2 Func Test2($aCoords) GUIDelete($hGUI) Exit MsgBox(0, "Event Test2", "The password was correct!" & @CRLF & @CRLF & "BTW: Your mouse coordinates are " & $aCoords[0] & ":" & $aCoords[1] & "!") - 1 EndFunc 2. Looping execution (+ custom delay)#include "GlobalEvents.au3" #include <Misc.au3> GUICreate("Test") $hLabel = GUICtrlCreateLabel("", 0, 190, 400, 20, 1) GUISetState() ; Set lower delay: _GlobalEvents_SetDelay(100) ; Looping event: _GlobalEvents_Create("_IsPressed('20')", SpacePressed, 2) _GlobalEvents_Create("_IsPressed('20')=0", SpaceNotPressed, 2) While GUIGetMsg() <>-3 ; here be code WEnd Func SpacePressed() DisplayMessage("Space is pressed (" & @SEC & ").") EndFunc Func SpaceNotPressed() DisplayMessage("Space is not pressed :(") EndFunc Func DisplayMessage($sText) If GUICtrlRead($hLabel) <> $sText Then GUICtrlSetData($hLabel, $sText) EndFunc DownloadSee attachments. Example.au3 Example_Continious.au3 Example_Minimal.au3 GlobalEvents.au3 coffeeturtle 1 I will answer every single PM, and you are free to ask anything anytime. Link to comment Share on other sites More sharing options...
JohnOne Posted September 20, 2015 Share Posted September 20, 2015 Just so people do not get excited, it should be noted that there are no events raised in this script, rather an adlibregister running a function that loops testing for your conditions. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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