Page 1 of 1

Script sending to two windows with the same name

Posted: 23 Jul 2020, 20:48
by dthomas0499
I am having an issue where my script is sending the keys to both windows I have open that happen to have the same name. One of them are a window I am playing on and the other is one that I want the script to run on. How do I make it so it only runs on a specific window?

Code: Select all

#IfWinActive, World of Warcraft
Loop  
{
	ControlSend,,{w down},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{w up},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,6,World of Warcraft	
	RandomSleep(10000,40000)
	ControlSend,,{a down},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{a up},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{d down},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{d up},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{s down},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{s up},World of Warcraft	
	RandomSleep(2000,5000)
	ControlSend,,{z down},World of Warcraft	
	RandomSleep(1000,1500)
	ControlSend,,{z up},World of Warcraft	
	RandomSleep(1000,1500)
}
return

RandomSleep(min,max)
{
Random, random, %min%, %max%
Sleep %random%
}

Re: Script sending to two windows with the same name

Posted: 23 Jul 2020, 22:32
by boiler
Use the Window Spy tool to see if they each have a different ahk_class or something. If not, then you can get the unique ID (HWND) of each and then decide which one is the one to target and use that. You should be able to determine which one to target by its size and/or position.

Re: Script sending to two windows with the same name

Posted: 25 Jul 2020, 00:56
by Pepineros
Presumably you're only running this script while playing, right? In that case you don't need to use #ifwinactive.

Can you try the following (untested, sorry), run this script _after_ you run both instances of WoW:

Loop
{
ControlSend,,{w down},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{w up},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,6,World of Warcraft,,A
RandomSleep(10000,40000)
ControlSend,,{a down},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{a up},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{d down},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{d up},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{s down},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{s up},World of Warcraft,,A
RandomSleep(2000,5000)
ControlSend,,{z down},World of Warcraft,,A
RandomSleep(1000,1500)
ControlSend,,{z up},World of Warcraft,,A
RandomSleep(1000,1500)
}
return

RandomSleep(min,max)
{
Random, random, %min%, %max%
Sleep %random%
}


If this hack doesn't work, your best bet will be to get the PIDs or HWNDs of both windows and using that in your controlsends instead.

Let me know