Jump to content

"delay" on event?


Recommended Posts

Hello there,

I'm new on this language and I'm currently learning about gui, controls, events, ...

So, in a basic gui (using setupgui for example), I asked myself: what would happen if the user trigger two (or more) events at the same time ?

I mean, I'm using an infinite loop to check events, so, theoretically, if I click a button, the defined action must be executed 'instantly' before anything else happens.

OK, but let's imagine a supersayen user click the button1, then 'instantly' (before the "select loop" runs) click button2, what happens? Logically, as I understood the "GUIGetMsg" function, this one should return the control ID of the last control (here, a button) used/clicked. Well, it's not clearly explained in the help file, so that's how I explain it rationally....

BUT, to be sure, I added a pause at the very start of the infinite loop. First, I've set the pause delay to 1000ms, and what happened is a ~10s delay before the action related to my button would happens... Wow! Mindfuck for me ! What is happening ? Trying to find an explanation, I added a counter in my loop, and wow, the loop runs 27 times before doing anything !

And after this, all the actions are executed, like if they were retarded, butt kept in memory....

 

So, can anyone please tell me what's happening ?

If it wasn't clear enough, tell me, but I'm sure it's simple to explain.... :/ Anyway I continue my 'training' because as for now, this 'problem' isn't really disturbing (except for my brain lol)

Thank you for reading my noob story :D

Link to comment
Share on other sites

  • Moderators

jeffonce,

Welcome to the AutoIt forums.

Firstly, there is no need to add a Sleep within the GUIGetMsg loop - the function has its own built-in delay of ~12ms to allow the CPU to breathe and adding a further pause just makes the GUI less responsive.

Next, the events that occur within the GUI are queued and dealt with in order, so you will see this sort of thing:

000ms - Start of loop
015ms - If no events, GUIGetMsg returns 0
...   - This continues until an event occurs
600ms - An event occurs and the event value (I.e. a button ControlID) is returned by GUIGetMsg.
        Whatever code is within that Case section of the loop is now actioned
        Let us say it takes 200ms to run, but another control is actioned within that time
800ms - Once back in the loop, GUIGetMsg returns the next event value.
        Note that the Case code for this event only runs now, not at the time the event actually occurred

if you want code to run immediately the event occurs, then you need to look at HotKeys, Windows message handlers, and the like which do not depend on the main idle loop of the script.

I hope that helps - please ask again if you still have questions.

M23
 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ooh okay !

So, events are simply queud and treated one by one ?

In other words, "GUIGetMsg" doesn't simply return the controlID of last control used, but will remember what control were used and tell these one by one at each call ?

I'm glad your understood me :D, thank you very much!

Link to comment
Share on other sites

Quote

AutoIt queues function calls in both OnEvent and MessageLoop modes. This means that it waits until a function is finished and the code is back in your idle While...WEnd loop before running the next.

from:  https://www.autoitscript.com/wiki/Interrupting_a_running_function

For understanding the diference of OnEvent and MessageLoop mode read https://www.autoitscript.com/autoit3/docs/guiref/GUIRef.htm

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...