autohotkey multi-threading

Get help with using AutoHotkey and its commands and hotkeys
Parama
Posts: 40
Joined: 27 Sep 2017, 22:38

autohotkey multi-threading

20 Nov 2017, 20:18

Code: Select all

f1::
loop
{
  controlsend,,{a}, title1 - notepad
}

return


f2::

loop
{
   controlsend,,{b}, title2 - notepad
}

return

for example, i wanna run hotkey f1, f2 simultaneously.(actual scripts are much more complicated.)
but can't run this because autohotkey is not multi-threading program
how can i run this?
User
Posts: 283
Joined: 26 Jun 2017, 08:12

Re: autohotkey multi-threading

20 Nov 2017, 20:52

here is an example of fake multi thread:

Code: Select all

f11 := f12 := 1

gui, add, text, h200 w200 vtext, 
gui, add, text, , Press f11\f12 to stop\continue thread
gui, show

loop
{

if (f11 = 1)
Count1++

if (f12 = 1)
Count2++

guicontrol, , text, % ""
. "f11 Thread: " Count1 "`n`n"
. "f12 Thread: " Count2 "`n"

sleep, 1000
}

guiclose:	;__________ gui close _________
exitapp

f11::	;_________ f11 thread _______

if (f11 = 1)
f11 := 0
else
f11 := 1

return



f12::	;_________ f12 thread _______

if (f12 = 1)
f12 := 0
else
f12 := 1

return
User avatar
Capn Odin
Posts: 1290
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: autohotkey multi-threading

20 Nov 2017, 21:06

In AutoHotkey_L the closest thing to multi-threading is to run multiple scripts at the same time. However it possible to achieve a similar effect using SetTimer, this will alternate between executing the difference threads instead of executing them at the same time.
AutoHotkey_H has native support of multi-threading see AhkThread.

Edit: here is an example using SetTimers

Code: Select all

#Persistent
SetTimer, Label1, 100
SetTimer, Label2, 100
return

Label1:
	ControlSend, ,{a}, title1 - notepad
return

Label2:
	ControlSend, ,{b}, title2 - notepad
return
Please excuse my spelling I am dyslexic.
A_User
Posts: 36
Joined: 21 Aug 2017, 01:15

Re: autohotkey multi-threading

22 Nov 2017, 15:38

There is a very useful function, LoadFile(), by lexikos. It creates separate processes using pipe and allows the main script to communicate with child processes by sharing objects. It's worth trying.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband and 127 guests