minxomat

GlobalEvents UDF - Create events on everything (with arguments)

2 posts in this topic

Introduction

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

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

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

 

Features

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

 

Examples

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

 

 

Download

See attachments. 

Example.au3

Example_Continious.au3

Example_Minimal.au3

GlobalEvents.au3

1 person likes this

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

    • pboom
      By pboom
      I am looking for a way to retrieve filtered messages from the ‘system debug channel.' also known as  ‘kernel-mode debug output.'

      AutoIt must do the capture in real time. The following AutoIt UDF almost does what is required but it only captures application level, or Win32 debug output.

      https://www.autoitscript.com/forum/topic/82889-capture-debug-information-udf/#comment-593268

      The utility DebugView by Sysinternals captures the information as required by turning on Capture Kernal and in my case using the Filter include:

      *Incoming connection*

      The use of DebugView to do this is covered in the following tech note;

      https://www.tacticalsoftware.com/support/tech-notes/logging-com-port-activity.htm

      https://technet.microsoft.com/en-us/sysinternals/debugview.aspx

      However to make to make the information from DebugView available to my AutoIt script required DebugView capture to a text file and then my AutoIt script monitor that file for changes. The use of DebugView to capture the system debug channel could be made to work, but it was less than reliable and difficult to get started. The startup wasn’t something that could be easily automated not even with AutoIt.

      If you understood what I am talking about and made it this far, I think an explanation of the application is in order. Lots of details here sorry trying to answer questions in advance.

      I support a large installation of General Electric MUSE application. MUSE is a Windows-based medical application that processes and archives ECGs (electrocardiograms) taken on dedicated hardware (ECG Carts). Several methods exist on the cart to get the ECG from the Carts to the MUSE system; they range from floppies (on old obsolete hardware), memory cards, RS232 serial ports, and hardwired network connections.

      In our installation, we choose not to use the vendor-supplied network solution due to a variety of reasons I won’t get into here.  Instead, we have designed our own connection solution.

      We use a wireless serial server mounted on the ECG carts connecting to a server running a Serial/IP COM Port Redirector. The ECG cart and MUSE application think they are talking to each other via an RS232 port and as far as they are concerned, they are. However, this RS232 cable happens to run through our province (think State) wide Health Care WAN.  The hardware and software used can be seen on these two sites;

      http://www.bb-elec.com/Products/Wireless-Cellular/AirborneM2M-802-11-a-b-g-n-Dual-Band-Wireless/AirborneM2M-Industrial-Dual-Band-Wi-Fi-Router-Brid.aspx

      https://www.tacticalsoftware.com/virtual-serial-port-redirector/serial-ip.htm

      This setup works well we have over 130 ECG carts connecting using this setup. However, the end users are not technical, and there is a lot that can go wrong with wireless connections. So we do get complaints, often after the fact, that the ECG cart would not connect. A log of what ECG carts connected and when would be very helpful.

      The Serial redirector software can be configured to log all activity to the Kernal-mode Debug output. The serial redirector software itself being kernel level software. For configuration of the Wireless modules, we have custom written software (written in AutoIt) that amongst other things can display relevant configuration information for a Wireless module given it’s IP address.

      By extracting messages like the ones below from the Kernal-Mode Debug channel;

      COM56 : ½ Incoming connection from 10.158.188.172:51562

      COM18 : ½ Incoming connection from 10.158.188.200:50896

      COM19 : ½ Incoming connection from 10.158.188.180:59074

      COM68 : ½ Incoming connection from 142.239.15.82:34322

      We can have the module configuration program retrieve the configuration. The retrieved configuration contains more information such as the module ID number and wireless signal strength. This information is then logged to a file which is later loaded into a database. We can then query the database for connections made by a particular module within a specified time frame. The results of these Queries help us determine if the module was connected or is having problems connecting. Problems are usually indicated by poor signal strength and frequent re-connecting.

      So what I am looking for is a way for our module configuration program (written in AutoIt) to retrieve filtered Kernal-Level debug messages directly without using the DebugView application.

      The Forum post listed at the first of this message includes the source code for the DLL. So if you are versed in these matters and Visual Studio this may be an easy task. I looked at what needed to be done but, I was way over my head. If you look up the price of the serial IP redirector software, you can see that there is some money in our project for such things however, I do have a spending limit for purchases such as this.

       
    • jollypk
      By jollypk
      hI,
      Is there any UDF for Zeromq ?
      I need to communicate with a remote and local socket. Any suggestion or guidance will be very appreciated.
       
      Thanks
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of:
      _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? 
      Thanks a lot for the help
      EDIT:
      Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2.
      Which are possible causes? Thanks a lot, again
      EDIT 2:
      ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ).
      Thanks  
      EDIT 3 ( bug ):
      Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation:
      wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me  
    • SorryButImaNewbie
      By SorryButImaNewbie
      Hello,
      I try to add a new UDF to my AutoIT library, and it seems I fail. I started to work following the insturctions found on the wiki . 
      I made an extra folder just next to my AutoIT folder, called ExtraUDF, and copied the file CUIAutomation2.au3 in it (I try to use this UDF for automating a program) then I run sciteconfig, set this folder up as User Include Folder, applied the changes, then run the calltip manager and got a msg when I tried to parse it. I attach a few pictures for better present the problem.
      I think I miss something here, should i put anything else on the ExtraUDF folder? I dont think that the CallTip manager added the udf to scite, If I try to run it i get a msg saying that I Scite cant open the include file and naturally after that, It can't use the functions called from it.
      Thank you for your help and insight as always! Please ask, if anything is fuzzy about the problem
       





    • Gowrisankar
      By Gowrisankar
      Good day to the members of the forum.. 
      Is there any UDF that is available to automate Attachmate Extra Mainframe sessions?
      I am trying to automate mainframe processes. I couldn't get values from particular co-ordinates in mainframe or pass values to particular co-ordinates in mainframe.
      Please let me know if there is any UDF or any other kind of solution is available. 
      Thanks and regards,
      Gowrisankar R.