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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

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

03 Aug 2018, 09:42

Hi all ;)

I have, for example, 5 NOX (android emulator) session open into my desktop and working on it with 5 game opened.
i make one single macro for mouseclick at specific coordinates into active windows ... and this it's not a problem ... after macro ending i activate other session and "macro-work" with next

my "goal" are to start working macro on active windows (with some mouse clicks on it) -> activate other windows and start other macro (with some mouse clicks on it) -> activate other window ecc. ... so:

- mouse clicks on window n.1 continue like programmed ...
- mouse clicks on window n.2 continue like programmed ...
- use "normally" mouse and keyboard on windows n.3 or 4 ecc.

BUT :-?

I think if AHK send mouse click on specific position and i'm working on other windows ... probably i have problem with mouse movment :crazy: ... and i know coordinates of "active window", if I activate other windows my "normal" macro go over the new activated :cry:

are possibilities to, for wxample, SendEvent {Click 100, 200} without interact with normal mouse operation and not in active windows ?

Any "idea" are welcome :thumbup:

EDIT: change title
Last edited by scriptors on 13 Aug 2018, 04:59, edited 1 time in total.
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: Best way (if possible) to have multiple macro on multiple application

06 Aug 2018, 12:02

I am having a hard time understanding the problem, but taking a look at controlClick may help. ControlClick lets you click on an inactive windows without actually using the mouse. To click on inactive windows you must specify which window you want to click on using the ahk_id rather than using the active window.
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: Best way (if possible) to have multiple macro on multiple application

07 Aug 2018, 01:53

Thanks, i try it ;)

write one example of part of my script:

Code: Select all

Mission_GG:
	Loop
	{
			PixelGetColor, Res, 435, 160, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
				}
				Sleep 500
				MouseClick, left, 435, 160 ; click Mission
	}
	Return
So i think must have two possibilities:
1. write two macro, one for "night working" (time-opens nox session, activate single windows and automatic work on it) and one for when i'm online and use more NOX session at same time with "ControlClik"
2. write one macro usable for night and morning session

.... i must make more knowledge about it

So ... I have, for example, 3 nox session opened ... "1", "2" and "3" ... then:

Code: Select all

Mission_GG:
	Loop
	{
			PixelGetColor, Res, 435, 160, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
				}
				Sleep 500
				ControlClick, x435 y 160, 1,,,, NA ; click Mission ... BUT it's work only for NOX window named "1" and NOT for all windows, so must make one for every windows
	}
	Return
BUT ... i think ... i need someone like "ControlPixelGetColor" :roll:
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: Best way (if possible) to have multiple macro on multiple application

07 Aug 2018, 08:23

Try this. It looks like your window names are integers so I just used a_index as their window name.

Code: Select all

;use absolute coordinates rather than relative so you dont have to activate any windows
CoordMode ,Pixel,Screen ;set this to use absolute coordinates
numberOfNOXWindows := 4 
Mission_GG:
	Loop
	{
		loop %numberOfNOXWindows%
		{
			guiName := A_index ; if all your window names are integers you can just us a_index as their name		
			
			WinGetPos , X, Y, Width, Height, %guiName%, ;get the position of the window you want to search
			newX := X + 435
			newY := Y + 160
			PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
			}
			Sleep 500
			tooltip % "x" . newX . " y" . newY
			ControlClick, x%newX% y%newY%, %guiName%,,,, NA ; this should click on every window using absolute coordinates
		}
	}
	Return
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

Re: Best way (if possible) to have multiple macro on multiple application

07 Aug 2018, 08:41

God idea :bravo:

I just think to solve problem by "position-fix the NOX-windows" and use absolute coordinates ... with your solution it's more clear how to make it :thumbup:

only problem it's to have two different AHK.macro because normally, i use ActiveWindows CoordMode for the "night macro"

i try this and post result ;) ... work must to be functional and completed :lol:

ps. and sorry for my bad english

EDIT: ... but I can change all "windows coordinates" by use windows name and relative position ;)
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

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

13 Aug 2018, 05:34

Hi again ;)

The solution from @colt are ok, but it make "one step" at time ... for some situation i need more time to make it for all my NOX session so i think about two solution:

1. make more file.ahk with macro for every single NOXSession (without activate it)
2. i don't know if it's possible to have more Loop run simultaneously and how to make it

For stupid things i use (like example):

Code: Select all

!^+a::
; first FIVE windows have the same dimension (small)
ControlClick, x435 y 160, N1,,,, NA ; click help button
Sleep 100
ControlClick, x435 y 160, N2,,,, NA ; click help button
Sleep 100
ControlClick, x435 y 160, N3,,,, NA ; click help button
Sleep 100
ControlClick, x435 y 160, N4,,,, NA ; click help button
Sleep 100
ControlClick, x435 y 160, N5,,,, NA ; click help button
Sleep 100
; next FOUR windows have the same dimension (more big)
ControlClick, x385 y 125, N6,,,, NA ; click help button
Sleep 100
ControlClick, x385 y 125, N7,,,, NA ; click help button
Sleep 100
ControlClick, x385 y 125, N8,,,, NA ; click help button
Sleep 100
ControlClick, x385 y 125, N9,,,, NA ; click help button
Sleep 100
Return
I must repeat this for 3 time (different coordinates for different things) and must add color control control for "safe" working ... but this are simply and stupid use of AHK :oops: ... but work

My goal are to, for example:

Code: Select all

;use absolute coordinates rather than relative so you dont have to activate any windows
CoordMode ,Pixel,Screen ;set this to use absolute coordinates
Mission_GG:
	Loop ; first Loop for N1 window
	{
			WinGetPos , X, Y, Width, Height, N1, ;get the position of the window N1
			newX := X + 435
			newY := Y + 160
			PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
			}
			Sleep 500
			tooltip % "x" . newX . " y" . newY
			ControlClick, x%newX% y%newY%,N1,,,, NA ; click on N1 window using absolute coordinates ... work for 10 clicks and 10 seconds
	}
	Loop ; second Loop for N2 window
	{
			WinGetPos , X, Y, Width, Height, N2, ;get the position of the window N2
			newX := X + 435
			newY := Y + 160
			PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
			}
			Sleep 500
			tooltip % "x" . newX . " y" . newY
			ControlClick, x%newX% y%newY%,N2,,,, NA ; click on N2 window using absolute coordinates ... work for 10 clicks and 10 seconds
	}
.... other Loop
	Return
	
Of course this situation make first loop one then loop two ... and are not good for me

I must try to make N1.ahk and N2.ahk (run at some time) with:

N1.ahk

Code: Select all

;use absolute coordinates rather than relative so you dont have to activate any windows
CoordMode ,Pixel,Screen ;set this to use absolute coordinates
!^m:: ; just for example
	Loop ; first Loop for N1 window
	{
			WinGetPos , X, Y, Width, Height, N1, ;get the position of the window N1
			newX := X + 435
			newY := Y + 160
			PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
			}
			Sleep 500
			tooltip % "x" . newX . " y" . newY
			ControlClick, x%newX% y%newY%,N1,,,, NA ; click on N1 window using absolute coordinates ... work for 10 clicks and 10 seconds
	}
	
N2.ahk

Code: Select all

!^m:: ; just for example
	Loop ; second Loop for N2 window
	{
			WinGetPos , X, Y, Width, Height, N2, ;get the position of the window N2
			newX := X + 435
			newY := Y + 160
			PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
			if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
				Sleep 2000
				break  ; Terminate the loop
			}
			Sleep 500
			tooltip % "x" . newX . " y" . newY
			ControlClick, x%newX% y%newY%,N2,,,, NA ; click on N2 window using absolute coordinates ... work for 10 clicks and 10 seconds
	}
	Return
i don't know if the same !^m:: call at some time the two loop ... but try

sorry for my english and ... i hope you understand me and have more "professional" solution for solve this :thumbup:
colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

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

13 Aug 2018, 08:52

I think I understand your problem. Use setTimer so you get multithreading behavior. If you use set timer your sleep commands will run independent and won't interfere with the rest of the program while still having all your code in one script.

Something like This

Code: Select all

setTimer t1,500
setTimer t2,500
;these two timers will be running in parallel
t1:
	WinGetPos , X, Y, Width, Height, N1, ;get the position of the window N1
	newX := X + 435
	newY := Y + 160
	PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
	if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
		Sleep 2000
		break  ; Terminate the loop
	}
	Sleep 500
	tooltip % "x" . newX . " y" . newY
	ControlClick, x%newX% y%newY%,N1,,,, NA ; click on N1 window using absolute coordinates ... work for 10 clicks and 10 seconds	
return

t2:
	WinGetPos , X, Y, Width, Height, N2, ;get the position of the window N1
	newX := X + 435
	newY := Y + 160
	PixelGetColor, Res, %newX%, %newY%, RGB ; Gets the colour at the coordinates (x, y) in the active window
	if(Res = 0x3F4D5D or Res = 0x394B58){ ; checks if MISSION are END
		Sleep 2000
		break  ; Terminate the loop
	}
	Sleep 500
	tooltip % "x" . newX . " y" . newY
	ControlClick, x%newX% y%newY%,N2,,,, NA ; click on N2 window using absolute coordinates ... work for 10 clicks and 10 seconds	
return
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

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

13 Aug 2018, 10:05

well, i try it ... but:

Threads: https://autohotkey.com/docs/misc/Threads.htm
... Although AutoHotkey doesn't actually use multiple threads, it simulates some of that behavior ...
i try with simply and small loop and test how work ;)
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

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

13 Aug 2018, 12:00

i have poor result ... but depend by my poor knowledge :?

i must use ControlClick with internal Windows coorinates ;) ... so if i use !^k:: one part of macro work correctly

Code: Select all

!^g::
setTimer N4, 500
setTimer N5, 500
Return

N4:
!^k::
Loop
{
	WinGetPos , X, Y, Width, Height, 4, ;get the position of the window 4
		newX4 := X + 320
		newY4 := Y + 120
		PixelGetColor, Res, %newX4%, %newY4%, RGB ; Gets the colour at the coordinates (x, y) in the active window
		if(Res = 0x3F4E5C or Res = 0x3F4E5C){ ; checks if MISSION are ON
		Sleep 500
		MsgBox finito
		break  ; Terminate the loop
		}
	Sleep 500
;	tooltip % "x" . newX4 . " y" . newY4
	ControlClick, x320 y120, 4,,,, NA ; click on N4 window using internal coordinates (absolute coordinates NOT work)
	Sleep 300
}
return

N5:
Loop
{
	WinGetPos , X, Y, Width, Height, 5, ;get the position of the window N5
		newX5 := X + 320
		newY5 := Y + 120
		PixelGetColor, Res, %newX5%, %newY5%, RGB ; Gets the colour at the coordinates (x, y) in the active window
		if(Res = 0x3F4E5C or Res = 0x3F4E5C){ ; checks if MISSION are ON
		Sleep 500
		MsgBox finito
		break  ; Terminate the loop
		}
	Sleep 500
;	tooltip % "x" . newX5 . " y" . newY5
	ControlClick, x320 y120, 5, , , , NA ;  click on N5 window using internal coordinates (absolute coordinates NOT work) 
	Sleep 300
}
return
scriptors
Posts: 227
Joined: 25 Feb 2016, 09:01

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

13 Aug 2018, 12:11

Adjust some mistake ... now work but:

first finish on Window N5 and after start on window N4 :wtf:
Spoiler

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 338 guests