AHK_H Prepare code on thread, then run it Topic is solved

Ask for help, how to use AHK_H, etc.
SlimeBrow
Posts: 13
Joined: 06 Aug 2020, 11:59

AHK_H Prepare code on thread, then run it

03 Feb 2022, 08:05

Hi,

My question is, can I prepare code on a specific thread, then run it afterwards?
Meaning, can I for example add `ControlSend,, {F11}, Somewindow` to a thread, then run it later?
Currently, to send keys to multiple windows at once, when hitting one button, I do this:

Code: Select all

sendThread1.AddScript("ControlSend,, {F11}, Window1", 2)
sendThread2.AddScript("ControlSend,, {F11}, Window2", 2)
sendThread3.AddScript("ControlSend,, {F11}, Window3", 2)
I'm asking, because whenever I hit the button that is mapped to this code, it has a small delay to actually send that input.
This is the real problem, but I am guessing this delay happens, because it takes some time for AHK_H to add that code to that thread, and then to run it.

Any help is appreciated, thank you! :)
SlimeBrow
Posts: 13
Joined: 06 Aug 2020, 11:59

Re: AHK_H Prepare code on thread, then run it

19 Feb 2022, 13:42

Sorry for the late response, I haven't seen your message, even though I looked in the inbox regularly :/

Anyways, the delay is pretty short, and it is bearable, but I do often use this shortcut, and sometimes I get confused because of this delay, because the program is pretty heavy and loads some stuff whenever it gets activated etc.
But, I just prefer to have a lighter solution than always giving the threads new code, which is always the same code, to execute, instead of caching it or something. I sometimes use 12 threads on one key press, sending new code (that is always the same) for each thread is kind of bad, and there must me a better solution, at least that is what my intuition says ¯\_(ツ)_/¯

Thank you for the help :)
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: AHK_H Prepare code on thread, then run it  Topic is solved

19 Feb 2022, 19:38

I normally load all the required code in each thread so I can use it whenever I need it, try that.
You can execute the code you added later, use ExecuteLine (addScript will return the added line pointer) or ahkLabel.
SlimeBrow
Posts: 13
Joined: 06 Aug 2020, 11:59

Re: AHK_H Prepare code on thread, then run it

21 Feb 2022, 02:43

Ohhhhh, so that's how it works.... Now I get it! I've been trying to do this for a long time, but I just didn't understand that addScript returns a pointer, that can be used in ahkExecuteLine!
Thank you :)

Here's my code if someone needs it, or has any suggestions etc.

Code: Select all

sendThread := ahkThread("#Persistent`n#NoTrayIcon")
activate   := sendThread.AddScript("ControlSend,, {F11}, Window1", 0)

; (Some code)

sendThread.ahkExecuteLine(activate, 1, 0)

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 3 guests