1
votes

I have a .ahk script file with 3 hotkeys.

Each hotkey takes a few seconds to complete.

What happens when I run hotkey a and then hotkey b before a is finished is that a is interrupted and the script continues with b.

Basically I want a and b to run concurrently.

Can I achieve this ?

2

2 Answers

1
votes

When I need two functions to operate simultaneously I make multiple scripts that interact with each other. Unfortunately Autohotkey doesn't support multi-threading so that's the only way to do it.

Some ideas:

  • You can pass variables between scripts using msgbox and/or GUIs.

  • You can also use msgbox as a "wait until" if you need one function to wait for the other to complete a part of automation.

  • I sometimes use that to make two scripts "play tag" to utilize all the down time that exists during load times on websites. In other words, I make two bots that interact with separate websites... automating one while the other one is waiting for its page to load.

  • I have also utilized a "control panel" type of setup where I make a master script that controls subroutines (other scripts) via GUIs. You can then use the buttons to trigger Run commands and provide kill buttons for each subroutine. This will give it the feeling of a full application if you do it all through controlsend to a hidden gui. The master script can then keep track of all the variables that need to be exchanged between subroutines with msgbox like I mentioned before. But I think at that point you might want to just incorporate another more powerful language like python or Java.

0
votes

True Multi-Threading in a single script does not exist (yet) in AutoHotkey.

While there are some ways to try and create "fake" multithreading, the best solution at the present is to have each hotkey run their own separate ahk script files using the Run command.


Hope this was helpful; if you would like an example of what this kind of code would look like, lmk and I can go ahead and create one.