New AHK Script to send one input to multiple .exe

Ask gaming related questions (AHK v1.1 and older)
mousline
Posts: 4
Joined: 18 Jan 2022, 01:36

New AHK Script to send one input to multiple .exe

Post by mousline » 18 Jan 2022, 01:46

Hello,

I'm looking for a .ahk that would send for example the key 4 to eight .exe windows when I press 4 on the first one... It is for a game called Dark Age of Camelot. If anyone could help me that would be great :)

Thank you,

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

Re: New AHK Script to send one input to multiple .exe

Post by mikeyww » 18 Jan 2022, 06:03

What are the programs of the other windows?

An example is below.

Code: Select all

winTitle = ahk_exe notepad.exe
#If hWnd := WinActive(winTitle)
~4::
WinGet, win, List, %winTitle%
Loop, %win% {
 If (win%A_Index% = hWnd)
  Continue
 WinActivate, % "ahk_id " win%A_Index%
 Send 4 ; Alternative may be ControlSend
}
Return
#If

mousline
Posts: 4
Joined: 18 Jan 2022, 01:36

Re: New AHK Script to send one input to multiple .exe

Post by mousline » 18 Jan 2022, 12:25

mikeyww wrote:
18 Jan 2022, 06:03
What are the programs of the other windows?

An example is below.

Code: Select all

winTitle = ahk_exe notepad.exe
#If hWnd := WinActive(winTitle)
~4::
WinGet, win, List, %winTitle%
Loop, %win% {
 If (win%A_Index% = hWnd)
  Continue
 WinActivate, % "ahk_id " win%A_Index%
 Send 4 ; Alternative may be ControlSend
}
Return
#If

Hello,

Here are two screenshots of the program in question, not sure which one you needed so I just sent both:

https://prnt.sc/26f8z0k
https://prnt.sc/26f8z7e

I'm noob at ahk would I just change the (winTitle) to the name of the program?

also do the windows have to be in windowed or is windowed fullscreen fine?

Thank you :)

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

Re: New AHK Script to send one input to multiple .exe

Post by mikeyww » 18 Jan 2022, 12:49

Yeah, I would just try it. Could use winTitle = Dark Age of Camelot at the top. See what happens.

mousline
Posts: 4
Joined: 18 Jan 2022, 01:36

Re: New AHK Script to send one input to multiple .exe

Post by mousline » 18 Jan 2022, 13:00

mikeyww wrote:
18 Jan 2022, 12:49
Yeah, I would just try it. Could use winTitle = Dark Age of Camelot at the top. See what happens.
It does work thank you so much however there is one thing, it changes clients and presses the number 4, is there a way to control only one client (the main character) and have 7 other just press the key 4 without ever switching to them?

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

Re: New AHK Script to send one input to multiple .exe

Post by mikeyww » 18 Jan 2022, 13:06

Some windows will not respond to ControlSend, but you can try it.

Code: Select all

winTitle = Dark Age of Camelot
#If hWnd := WinActive(winTitle)
~4::
WinGet, win, List, %winTitle%
Loop, %win%
 If (win%A_Index% != hWnd)
  ControlSend,, 4, % "ahk_id " win%A_Index%
Return
#If
Other tips sometimes needed: https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/

mousline
Posts: 4
Joined: 18 Jan 2022, 01:36

Re: New AHK Script to send one input to multiple .exe

Post by mousline » 18 Jan 2022, 13:23

mikeyww wrote:
18 Jan 2022, 13:06
Some windows will not respond to ControlSend, but you can try it.

Code: Select all

winTitle = Dark Age of Camelot
#If hWnd := WinActive(winTitle)
~4::
WinGet, win, List, %winTitle%
Loop, %win%
 If (win%A_Index% != hWnd)
  ControlSend,, 4, % "ahk_id " win%A_Index%
Return
#If
Other tips sometimes needed: https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/

Does not work with the controlsend but I'll make due with the first one thank you very much!

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: New AHK Script to send one input to multiple .exe

Post by Xtra » 18 Jan 2022, 14:06

When using ControlSend you can try using SetKeyDelay at the top of your script.
SetKeyDelay, 50, 50
The value of SetKeyDelay determines the speed at which keys are sent. If the target window does not receive the keystrokes reliably, try increasing the press duration via the second parameter of SetKeyDelay

You can also try using ahk_parent:
ControlSend, ahk_parent, 4, % "ahk_id " win%A_Index%
If this parameter is ahk_parent, the keystrokes will be sent directly to the target window instead of one of its controls

Post Reply

Return to “Gaming Help (v1)”