Auto spamming in two windows of same name

Ask gaming related questions (AHK v1.1 and older)
based person
Posts: 3
Joined: 18 Apr 2021, 16:10

Auto spamming in two windows of same name

Post by based person » 18 Apr 2021, 16:19

Hello. I've been attempting to create a code that auto spams messages for me in two inactive windows of same name. I tried to use the window handle however it did not appear to work. Forgive me if this is a silly mistake, I am quite new to AHK and do not happen to know what to do in this situation. Here is my code:

Code: Select all

#SingleInstance Force
GroupAdd, PanZoom, ahk_exe game.exe hwnd1
GroupAdd, PanZoom, ahk_exe game.exe hwnd2
Return



F4::
Loop
{
Send, {Enter}
Sleep 1000
Send, my message here
Send, {Enter}
Sleep 8000
}
Return
#IfWinActive

F5::
Reload
Return

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Auto spamming in two windows of same name

Post by mikeyww » 18 Apr 2021, 16:31

Code: Select all

F4::
WinGet, win, List, ahk_exe notepad.exe
Loop, %win% {
 WinActivate, % "ahk_id " win%A_Index%
 Send abc
}
MsgBox, 64, Done, Done!
Return

based person
Posts: 3
Joined: 18 Apr 2021, 16:10

Re: Auto spamming in two windows of same name

Post by based person » 18 Apr 2021, 16:59

@mikeyww
Hello, I modified the code you sent me and it worked, not as intended but it did. However I'd like it to switch between windows once the command is done, and it does so but only once, even though there is a "loop" command there. What am I doing wrong? (don't mind the "send a/d down/up", those are anti anti-spam measures.)

Code: Select all

 
F4::
Loop
{
 WinGet, win, List, ahk_exe game.exe
 WinActivate, % "ahk_id " win%A_Index%
 Send {enter}
 Sleep 1000
 Send, my message here
 Send {enter}
 Sleep 2000
 Send {d down}
 Sleep 50
 Send  {d up} 
 Sleep 100
 Send {a down}
 Sleep 50
 Send {a up}
 Sleep 4000
}
Return


F5::
Reload
Return

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Auto spamming in two windows of same name

Post by mikeyww » 18 Apr 2021, 17:13

Start with my script. Replace my Send with your Send. Change "notepad" to "game". Now compare. See the difference from your original?

If you seek an infinite loop:

Code: Select all

F4::
Loop {
 WinGet, win, List, ahk_exe game.exe
 Loop, %win% {
  WinActivate, % "ahk_id " win%A_Index%
  Send abc
 }
}
Or:

Code: Select all

F4::
WinGet, win, List, ahk_exe game.exe
Loop {
 Loop, %win% {
  WinActivate, % "ahk_id " win%A_Index%
  Send abc
 }
 Sleep, 500
}
Your script loops through an infinite number of windows that do not exist, because A_Index continues to increase.

based person
Posts: 3
Joined: 18 Apr 2021, 16:10

Re: Auto spamming in two windows of same name

Post by based person » 18 Apr 2021, 17:33

Thanks, it worked now, sorry for making such silly mistakes!!

Post Reply

Return to “Gaming Help (v1)”