Sign in to follow this  
Followers 0
planch

Script Flow Question

5 posts in this topic

Hey,

I'm not sure if this is the right forum for this type of question, but here it goes. I was trying to decide whether to write a small program using AU3 or Python with AutoItX, and I was wondering how AutoIt controls the script flow in the following example:

RegisterHotkey('{F1}','Pause')
Function Main()
   Do
      ... stuff ...
      Sleep(1000)
   Until 1
EndFunc 

Func Pause()
   MsgBox(1,'Alert','Paused')
EndFunc

Basically, what I'm wondering is how AutoIt stops the currently executing function 'Main' and moves to a completely different function 'Key' when the hotkey is pressed. I can't think of a good way to duplicate this in Python without using threads and checking for a Lock or Event every other line, and that still doesn't do the suspension. Does AutoIt accomplish this using something similar that's just invisible to the scriptwriter?

I'd appreciate it if any knowledgeable coders could enlighten me, and sorry if the question is a little confusing. I'm not a professional programmer or anything, so my understanding might be flawed.

Share this post


Link to post
Share on other sites



Hey,

I'm not sure if this is the right forum for this type of question, but here it goes. I was trying to decide whether to write a small program using AU3 or Python with AutoItX, and I was wondering how AutoIt controls the script flow in the following example:

RegisterHotkey('{F1}','Pause')
Function Main()
   Do
      ... stuff ...
      Sleep(1000)
   Until 1
EndFunc 

Func Pause()
   MsgBox(1,'Alert','Paused')
EndFunc

Basically, what I'm wondering is how AutoIt stops the currently executing function 'Main' and moves to a completely different function 'Key' when the hotkey is pressed. I can't think of a good way to duplicate this in Python without using threads and checking for a Lock or Event every other line, and that still doesn't do the suspension. Does AutoIt accomplish this using something similar that's just invisible to the scriptwriter?

I'd appreciate it if any knowledgeable coders could enlighten me, and sorry if the question is a little confusing. I'm not a professional programmer or anything, so my understanding might be flawed.

I assume that RegisterHotKey should be HotKeySet.

With hotkeys the program flow is diverted to the function set for the hot key after which it returns and continues. If the function called by the hot key is running and another hot key is pressed then that function is run and so on.


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.

Share this post


Link to post
Share on other sites

I assume that RegisterHotKey should be HotKeySet.

With hotkeys the program flow is diverted to the function set for the hot key after which it returns and continues. If the function called by the hot key is running and another hot key is pressed then that function is run and so on.

Yea, RegisterHotKey is the Python function, oops.

I can see it works like that from running the example, but how does it accomplish it? I know it's more of an academic question than a practical one, but I'm just trying to understand the language better.

Share this post


Link to post
Share on other sites

Yea, RegisterHotKey is the Python function, oops.

I can see it works like that from running the example, but how does it accomplish it? I know it's more of an academic question than a practical one, but I'm just trying to understand the language better.

Maybe this example by covaks gives an insight.


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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Maybe this example by covaks gives an insight.

Ok I don't think I'm asking the question clearly. I understand how to use the HotKeySet function, and what it does in the script. What I was curious is how AutoIt makes this happen 'behind the scene' as it were. This is probably more a question for one of AutoIt's developers, as it is about the interpreter itself and not the language specifically. That's why I didn't know if this was the correct forum to post it in. I'm just curious how this functionality is implemented (as I was trying to contrast it with Python, since I can't think of a simple way to do it). Now that I think about it though, it's a lot simpler than I thought if the interpreter just checks for HotKeys between each line and branches out into the associated code.

I don't even know if something like that is possible in Python without using complicated multitasking, which is overkill for the simple ability to bind a key that pauses your script whatever its location. I guess native AutoIt has some advantages over just using it through COM afterall. :)

Anyway, sorry if I was way off topic for this forum. It is probably appropriate for a Python forum now. Thanks for the responses though!

Edited by planch

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
Sign in to follow this  
Followers 0