Page 1 of 1

multi loop with autohotkey_h or autohotkey_dll

Posted: 28 Jul 2021, 15:00
by rj8810
hello, thanks in advance for any help..
somepeople could give me an example of multiple threads with 4 loops running at the same time ... I really appreciate autohotkey, since it has helped a lot people with disabilities, and I have read the autohotkey manual for months, and a little autohotkey_h and autohotkey_dll, but I feel really lost, could somepeople help me convert the following codes into multi-threads?:

script:

Code: Select all

;thread 1
Loop
{
	sleep 50
IfWinActive, Sin título: Bloc de notas
{
notes:=1
WinGetPos , X, Y, 
MsgBox %notes%in %x%%y%

}
else
{
	MsgBox, no activo
}
}

;thread 2
Loop
{
	sleep 50
	KeyIsDown := GetKeyState("l" , "P")
	MsgBox, %KeyIsDown%

}

;thread3
Loop
{
	sleep 50
	MouseGetPos , OutputVarX, OutputVarY
			
}


;thread 4
Loop
{
	sleep 50
	pluser:= X Y KeyIsDown OutputVarX OutputVarY
	tooltip:=%pluser%
	if pluser = 5005001500500
	{
		MsgBox %pluser%
	}
	
}
[Mod edit: [code][/code] tags added.]
I ask this favor since autohotkey normally wouldn't keep the values ​​of the varible pluser updated inside a loop....
I know that this could be done with a single loop, but this is an example for a starting point, on the other hand, when a script needs values ​​in real time, it may be that with a single loop when the "pluser" variable is updated, the The position of the window, the position of the mouse or the state of the key have already changed, taking into account that the pluser variable is the last line of the script.
thank you very much in advance any help...

Re: multi loop with autohotkey_h or autohotkey_dll

Posted: 28 Jul 2021, 19:28
by HotKeyIt
Try that:

Code: Select all

thread1:=AhkThread("
(
Loop
{
	sleep 50
	IfWinActive, Sin título: Bloc de notas
	{
		notes:=1
		WinGetPos , X, Y,
		MsgBox `%notes`%in `%x`%`%y`%
	} else 
		MsgBox, no activo
}
)")
thread2:=AhkThread("
(
Loop
{
	sleep 50
	KeyIsDown := GetKeyState("l" , "P")l
	MsgBox, `%KeyIsDown`%
}
)")

thread3:=AhkThread("
(
Loop
{
	sleep 50
	MouseGetPos , OutputVarX, OutputVarY
}
)")

thread4:=AhkThread("
(
Thread1:=Object(" (&thread1) ")
Thread2:=Object(" (&thread2) ")
Thread3:=Object(" (&thread3) ")
Loop
{
	sleep 50
	pluser:= thread1.ahkgetvar(`"X`") thread1.ahkgetvar(`"Y`") thread2.ahkgetvar(`"KeyIsDown`") thread3.ahkgetvar(`"OutputVarX`") thread3.ahkgetvar(`"OutputVarY`")
	tooltip:=`%pluser`%
	if pluser = 5005001500500
	{
		MsgBox `%pluser`%
	}
}
)")
Esc::ExitApp