Run multiple macro at the same time (for multiple application) Topic is solved

Ask for help, how to use AHK_H, etc.
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Run multiple macro at the same time (for multiple application)

27 Aug 2018, 04:09

Hi all ;)

I have "problem" with standard AHK because it's NOT multithread so ... found this :clap:

Now, ask if it's possible to do this "simple" macro:

i have 15 NOX (android simulator) windows open with the same game and want to make the same "macro" on all NOX windows in the same time:

Code: Select all

!^a::
;Click
Loop
{
	PixelGetColor, Res, 435, 160, RGB ; Gets the colour at the coordinates (x, y) in the active window
		if(Res = 0x384A59 or Res = 0x394B58 
		or Res = 0x3F4D5C or Res = 0x3E4C5C
		or Res = 0x3F4D5D or Res = 0x3F4D5D){ ; checks if MISSION are ON
		Sleep 500
		; verifica
		break  ; Terminate the loop
		}
	Sleep 500
	MouseClick, left, 435, 160 ;click Mission
}
return
This work ok on single NOX session (activate) , the question is: how to translate in multithread for work on 15 different windows ??

if it's possible of course ;)

I think it's impossible to make "active" 15 windows at the some time, so must change CoordMode to Screen and use ControlClick ecc.


EDIT: please move to Ask for Help section .. sorry :oops:
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run multiple macro at the same time (for multiple application)

27 Aug 2018, 15:33

You will have to check if ControlClick works and all windows would need to be side by side so PixelGetColor will work.
You will need find the window position and get the relative coordinates.
Script would be something like this (above not applied), depending on how you want to control it:

Code: Select all

!^a::
;Click
Loop 15 {
	ahk%A_Index%:=AhkThread("
(
Loop
{
	PixelGetColor, Res, 435, 160, RGB ; Gets the colour at the coordinates (x, y) in the active window
		if(Res = 0x384A59 or Res = 0x394B58 
		or Res = 0x3F4D5C or Res = 0x3E4C5C
		or Res = 0x3F4D5D or Res = 0x3F4D5D){ ; checks if MISSION are ON
		Sleep 500
		; verifica
		break  ; Terminate the loop
		}
	Sleep 500
	MouseClick, left, 435, 160 ;click Mission
}
)")
}
return
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

29 Aug 2018, 04:12

Great ... so i just create one or more thread and use it.
I haven't time to realize some script, just download and use/substitute AutoHotkey_H ;) ... then my idea, NOT tested, and just for "test about correct thread syntax":

Code: Select all

ClickOnButton(NameOfWindows, xxxx, yyyy, color1, color2, p0xxxx, p0yyyy) ;create function because windows have different position and size
	{
	Loop
		{
		PixelGetColor, Res, p0xxxx, p0yyyy, RGB ; Gets the colour at the coordinates (x, y) in the screen
		if(Res = color1 or Res = color2)
			{ ; checks if MISSION are ON
			Sleep 500
			break  ; Terminate the loop
			}
		Sleep 500
		ControlClick, %NameOfWindows%, x%xxxx%, y%yyyy%,,,, NA ;click on button
		}
	}
	
!^a::
CoordMode, Pixel, Screen
ahk_1 := AhkThread("
(
ClickOnButton(window_1, 100, 200, 0x3F4D5D, 0x394B58, -800, -400) ;i have two monitors
)")
ahk_2 := AhkThread("
(
ClickOnButton(window_2, 150, 250, 0x3F4D5D, 0x394B58, 1000, 800) ; just for put some number
)")

ahkthread_free(ahk_1),ahk_1:="" ; Stop execution in thread and free resources.
ahkthread_free(ahk_2),ahk_2:="" ; Stop execution in thread and free resources.

CoordMode, Pixel, Window 
Return
Every Loop need about 20/30 sec to finish ... so my idea are to start one Loop, then start the other ... everyone with/in different thread ... so all work in the same time

EDIT: ... or it's good idea to put "Stop execution in thread and free resources" at the end of Loop into the function ?
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run multiple macro at the same time (for multiple application)

29 Aug 2018, 15:02

It would not work that way since your coordinates would be the same, you will have to calculate coordinates inside the loop, you can use WinGet to cycle through all windows.
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

30 Aug 2018, 13:10

Well, I have make one "running" thread :thumbup: ... but have strange problem ... someone "solved" and someone not :shock:

sorry for too many ";" but i want to "store" old code ;)

1. if i set CoordMode to Screen, at the begin of script ... of course it not work for the new thread, so add CoordMode into begin of the new thread and it work perfectly ;)
2. script work perfectly but if i use "ahkthread_free(ahk_Buldrain),ahk_Buldrain:="" " ... it stop to work :?: why :shifty:

now the script

Code: Select all

!^z::
ahk_Buldrain:=AhkThread("
	(
CoordMode ,Pixel,Screen ; set this to use absolute coordinates ... and for specific thread ??? ... yes, it work
	Loop
	{
		; Window Position X: -1680 Y: 758 -> X:(-1608+348=-1332) Y:(758+118=876)
		PixelGetColor, Res, -1332, 876, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x395061 or Res = 0x395061){ ; checks if PACCHETTO are ON
			Sleep 2000
			;MsgBox Finito
			break  ; Terminate the loop
			}
	Sleep 500
						;MouseClick, left, 325, 264
	ControlClick, x325 y264, Buldrain,,,, NA
	Sleep 100
						;MouseClick, left, 325, 228
	ControlClick, x325 y228, Buldrain,,,, NA
	Sleep 100
						;MouseClick, left, 325, 192
	ControlClick, x325 y192, Buldrain,,,, NA
	Sleep 100
						;MouseClick, left, 325, 151
	ControlClick, x325 y151, Buldrain,,,, NA
	Sleep 100
						;MouseClick, left, 325, 114
	ControlClick, x325 y114, Buldrain,,,, NA
	Sleep 300
						;MouseClick, left, 325, 83
	ControlClick, x325 y83, Buldrain,,,, NA
	Sleep 100
	}

)")
;ahkthread_free(ahk_Buldrain),ahk_Buldrain:="" ; Stop execution in thread and free resources. Why this "stop" working of the script ?
Return
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run multiple macro at the same time (for multiple application)

30 Aug 2018, 16:05

Simply do ahk_Buldrain:="", rest will be done automatically.
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

31 Aug 2018, 04:47

Thanks ;)

Now i need to start one other thread like for other window ... just change mouse and color coordinates.
Easy way are to make other HotKey (!^x:: for example) ... but for start two, or more, thread with only one HotKey ?
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

31 Aug 2018, 10:24

sorry, i make stupid question before ... just add, other "thread", next to the other ... work fine and it's really GREAT form me :superhappy:

now i must try more, more idea :D

Wonderfull AutoHotkey_H :clap:
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

02 Sep 2018, 08:40

Hi again, simply question about my stupid macro ... can i improve it into one more "professional way" ?

Code: Select all

;###########################################################################
!^+j::
GG_1:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -1210, 193, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x470 y167, 1,,,, NA
	}
)")
GG_1:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_2:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -650, 193, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x470 y167, 2,,,, NA
	}
)")
GG_2:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_Alex:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -90, 193, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x470 y167, Alex,,,, NA
	}
)")
GG_Alex:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_3:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -1210, 559, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x470 y167, 3,,,, NA
	}
)")
GG_3:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_4:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -650, 559, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x470 y167, 4,,,, NA
	}
)")
GG_4:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_5:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -90, 559, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x470 y167, 5,,,, NA
	}
)")
GG_5:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_Buldrain:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -1332, 888, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3D4C59 or Res = 0x3D4C59){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x348 y130, Buldrain,,,, NA
	}
)")
GG_Buldrain:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_miniLuigi:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -917, 888, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3D4C59 or Res = 0x3D4C59){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x348 y130, miniLuigi,,,, NA
	}
)")
GG_miniLuigi:="" ; Stop execution in thread and free resources.

; #############################################################################################

GG_Empy:=AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, -502, 888, RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3D4C59 or Res = 0x3D4C59){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x348 y130, Empy,,,, NA
	}
)")
GG_Empy:="" ; Stop execution in thread and free resources.
		
Return
Create a Function to begin one thread and pass to function pixel data ?
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run multiple macro at the same time (for multiple application)

02 Sep 2018, 13:25

It does not make sense to Stop execution in thread and free resources directly after starting the thread, I will not have a chance to do anything!
Here the function:

Code: Select all

myThread:=MyClickLoop(100,200,250,290)
MyClickLoop(xPixel,yPixel,xClick,yClick){
	return AhkThread("
	(
CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	Loop
	{
		PixelGetColor, Res, " xPixel ", " yPixel ", RGB ; Colore sfondo fine pacchetti
			if(Res = 0x3C4B58 or Res = 0x3C4B58){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x" xClick " y" yClick ", 1,,,, NA
	}
)")
}
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

03 Sep 2018, 07:05

It work fine now ;)

Code: Select all

^!t::
;myThread:=MyClickLoop(470,167,0x3C4A57,"1")
MyClickLoop(470,167,0x3C4B58,"1")
MyClickLoop(470,167,0x3C4B58,"2")
MyClickLoop(470,167,0x3C4B58,"3")
MyClickLoop(470,167,0x3C4B58,"4")
MyClickLoop(470,167,0x3C4B58,"5")

Return

MyClickLoop(xClick, yClick, color, wname) ;xClick,yClick = window click / color = color to find / wname = window name
	{
	return AhkThread("
	(
	xClick := " xClick "
	yClick := " yClick "
	color := " color "
	wname := " wname "
	CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	WinGetPos, X, Y, , , %wname%
	xPixel := X + xClick ;screen coords X for chek
	yPixel := Y + yClick ;screen coords Y for chek
	Loop
	{
		PixelGetColor, Res, %xPixel%, %yPixel%, RGB ; Colore sfondo fine pacchetti
			if(Res = color or Res = color){ ; checks if PACCHETTO are OFF
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x%xClick% y%yClick%, %wname%,,,, NA
	}
)")
}
Last edited by scriptors on 03 Sep 2018, 15:03, edited 2 times in total.
HotKeyIt
Posts: 1705
Joined: 29 Sep 2013, 18:35
Contact:

Re: Run multiple macro at the same time (for multiple application)

03 Sep 2018, 14:31

See the example above MsgBox " xClick "... instead of MsgBox %xClick%...
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

03 Sep 2018, 15:03

yes, last edit before, now work fine
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)

03 Sep 2018, 16:13

mmm ... it stop working when i change coords

Code: Select all

^!t::
; this WORKING
1:=MyClickLoop(470,167,0x3C4B58,"1")
2:=MyClickLoop(470,167,0x3C4B58,"2")
3:=MyClickLoop(470,167,0x3C4B58,"3")
4:=MyClickLoop(470,167,0x3C4B58,"4")
5:=MyClickLoop(470,167,0x3C4B58,"5")

Alex:=MyClickLoop(470, 167, 0x3C4B58, "Alex")

; this NOT WORKING
Buldrain:=MyClickLoop(384, 130, 0x3D4C59, "Buldrain")
miniLuigi:=MyClickLoop(384, 130, 0x3D4C59, "miniLuigi")
Empy:=MyClickLoop(384, 130, 0x3D4C59, "Empy")

Return
and i must change:

Code: Select all

	ControlClick, x%xClick% y%yClick%, %wname%,,,, NA
with

Code: Select all

	ControlClick, x%xClick% y%yClick%, " wname ",,,, NA
probably all function work with same data ... and i don't understand difference for: " FunctionVariable "
scriptors
Posts: 151
Joined: 25 Feb 2016, 09:01

Re: Run multiple macro at the same time (for multiple application)  Topic is solved

04 Sep 2018, 14:04

stupid error, I wrong the coordinates (must x348 and I wrote x384 :crazy: ) and then the function was not going ... so this is working function for call how many thread i like

this work at 100%

Code: Select all

^!t::
; first coords serie
1:=MyClickLoop(470,167,0x3C4B58,"1")
Alex:=MyClickLoop(470, 167, 0x3C4B58, "Alex")
; second coords serie
Buldrain:=MyClickLoop(348, 130, 0x3D4C59, "Buldrain")
miniLuigi:=MyClickLoop(348, 130, 0x3D4C59, "miniLuigi")
Empy:=MyClickLoop(348, 130, 0x3D4C59, "Empy")
Return

MyClickLoop(xClick, yClick, color, wname) ;xClick,yClick = window click / color = color to find / wname = window name
; variable send from caller must write: " var " note the space ;)
	{
	return AhkThread("
	(
	CoordMode ,Pixel,Screen ;set this to use absolute coordinates and for specific thread
	WinGetPos, X, Y, , , " wname "
	xPixel := X + " xClick " ;screen coords X for chek
	yPixel := Y + " yClick " ;screen coords Y for chek
	Loop
	{
		PixelGetColor, Res, %xPixel%, %yPixel%, RGB ; Note variable are calculated internally so %var%
			if(Res = " color " or Res = " color "){ ; checks if GIFT PACK are finish
			Sleep 2000
			break  ; Terminate the loop
			}
	Sleep 500
	ControlClick, x" xClick " y" yClick ", " wname ",,,, NA
	}
)")
}
It is true that 99% of the problems lie between the chair and the keyboard :lol:

Return to “Ask For Help”

Who is online

Users browsing this forum: No registered users and 20 guests