Page 1 of 1

How to send key to 2 different inactive windows

Posted: 26 Jul 2021, 18:28
by kaos
Hello guys
first off I am not a programmer^^' but I need help with a script.

I want to send a key to 2 different inactive windows every 3 seconds. I want it to pause when a window becomes active, and continue when both are inactive again.
this is my old code I have been messing with. For some reason it keeps sending g to the window2 eventho I have window1 active. O.o

pls help

Code: Select all

DetectHiddenWindows, On

wintitle = game title 1
wintitle2 = game title 2

#g::
Loop {
IfWinNotActive, %wintitle% && %wintitle2%
{
	controlsend,,g, %wintitle%,
	sleep, 50
	controlsend,,g, %wintitle2%,
	sleep, 2500
}
}
return

Re: How to send key to 2 different inactive windows  Topic is solved

Posted: 27 Jul 2021, 00:36
by Rohwedder
Hallo,
try:

Code: Select all

DetectHiddenWindows, On
wintitle = game title 1
wintitle2 = game title 2
#g::SetTimer, Games, 2550
Games:
If !WinActive(wintitle) && !WinActive(wintitle2)
{
	controlsend,,g, %wintitle%,
	sleep, 50
	controlsend,,g, %wintitle2%,
}
Return

Re: How to send key to 2 different inactive windows

Posted: 27 Jul 2021, 00:41
by mikeyww
Another one:

Code: Select all

For each, app in win := ["game title 1", "game title 2"]
 GroupAdd, wins, %app%
#g::
Loop {
 SetTimer, Go, 3000
 SoundBeep, 1500
 WinWaitActive, ahk_group wins
 SetTimer, Go, Off
 SoundBeep, 1000
 WinWaitNotActive
}
Go:
For each, app in win {
 ControlSend,, g, %app%
 Sleep, 50
}
Return

Re: How to send key to 2 different inactive windows

Posted: 01 Aug 2021, 11:48
by kaos
Hey it works thank you sooooo much :D I was really grinding my head against this thank you!^^