Jump to content

GlobalEvents UDF - Create events on everything (with arguments)

Recommended Posts



The 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)

Func Test1()
    MsgBox(0, "Test", "@SEC equals 30!")

This event will be triggered once, when @SEC is 30 and then die.



  • Create 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).



1. 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)

While GUIGetMsg() <> -3

; Event handler 1
Func Test1()
    MsgBox(0, "Event Test1", "GUI was created!")

; Event handler 2
Func Test2($aCoords)
    Exit MsgBox(0, "Event Test2", "The password was correct!" & @CRLF & @CRLF & "BTW: Your mouse coordinates are " & $aCoords[0] & ":" & $aCoords[1] & "!") - 1


2. Looping execution (+ custom delay)

#include "GlobalEvents.au3"
#include <Misc.au3>

$hLabel = GUICtrlCreateLabel("", 0, 190, 400, 20, 1)

; Set lower delay:
; Looping event:
_GlobalEvents_Create("_IsPressed('20')", SpacePressed, 2)
_GlobalEvents_Create("_IsPressed('20')=0", SpaceNotPressed, 2)

While GUIGetMsg() <>-3
    ; here be code

Func SpacePressed()
    DisplayMessage("Space is pressed (" & @SEC & ").")

Func SpaceNotPressed()
    DisplayMessage("Space is not pressed :(")

Func DisplayMessage($sText)
    If GUICtrlRead($hLabel) <> $sText Then GUICtrlSetData($hLabel, $sText)




See attachments. 





  • Like 1

I will answer every single PM, and you are free to ask anything anytime.

Share this post

Link to post
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

  • Similar Content

    • MFrancisca
      By MFrancisca
      I've been checking the logging UDFs in the wiki, mostly Log4a and Loga and I wanted to ask which one would you recommend for a script that will be executed remotely through PSExec. My main question is where the logs are located in that situation and if I can change that location to a custom one., because I need to retrieve them at the end of execution.
      So in a rough description the process is
      Open PSExec
      Send compiled AutoIT script to remote machine
      Execute script
      Copy logs from the remote to the local machine.
      Any opinions? 
    • caramen
      By caramen
      I watched _OL_ItemSend&_OL_ItemFind&_OL_ItemCreate in OutlookEx UDF but hmmm
      Since it use the test environnement i cant get the orders of the mail creation
      Can someone make me win some time of reading all exemples script and lead me how to do one ?
      That whould be lovely.
    • Tersion
      By Tersion
      Here the this wiki page with list of available UDFs for data compression. For my tasks I only need ZIP support, so I started looking at pure AutoIt UDFs without any 3rd party dlls. And found out that most of available realizations uses standard ("native method") Windows dll - "zipfldr.dll". So for now I chose ZIP UDF by wraithdu. I've tested it on Windows 7 (x64) and it seem works fine. But here the comment from another topic where user says that Windows 10 discontinued support of "zipfldr.dll". Now I confused. I don't have around any Windows 10 machine to tested it. So maybe someone could confirm or deny that? Or maybe would better to switch to UDF with 7zip dll?
      I need an advice...
    • TheSaint
      By TheSaint
      Here is the bare bones of a UDF I have started work on.
      Mostly just a proof of concept at this stage, and still need to add some functions and dress the UDF up a bit ... to look like a UDF ... though it has my own distinct styling, especially as I have never really developed a UDF before now .... used plenty and modified plenty though. I've even invented my own UDF variable naming convention, which I am sure some of you will be aghast at. I work with what feels best for me, but others are free to adapt if they wish.
      The idea is to emulate the simplicity of INI files, but gain the benefits of SQL.
      Two scripts are provided.
      (1) The UDF, a work in progress - SimpleSQL_UDF.au3
      (2) An example or testing script - UDF_Test.au3
      Another first for me, is creating a 2D array from scratch, never done that before, that I can recall ... never had a need, and even for 1 dimension arrays, for a long time now, I have just used _StringSplit to create them. So I needed a bit of a refresher course, which my good buddy @TheDcoder assisted me with ... not without some angst I might add. LOL
      SimpleSQL_UDF.zip  (12 downloads previously)
      (I have now completed all the functions I intended to. My next update will be a big improvement, bringing things more inline with my latest INItoSQL DB program changes.)
      Program requires the sqlite3.dll, not included, but easily enough obtained.
      Hopefully the usage is self-evident ... just change the Job number variable in the UDF_Test.au3 file to check the existing functions out.
      P.S. This is also related to a new program I have just finished and uploaded - INItoSQL DB
    • xtcislove
      By xtcislove
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")