use 2 buttons with a small delay to target a specific window

Ask gaming related questions (AHK v1.1 and older)
muggie23
Posts: 9
Joined: 08 Feb 2023, 21:14

use 2 buttons with a small delay to target a specific window

Post by muggie23 » 08 Feb 2023, 21:17

Requesting help with a fairly simple script thank you!

Hi I am looking to use 2 buttons on keyboard with a small delay in between. But I need it to target a specific window (which is a game)
I will have 2 windows of the same game open though, so not sure how it would differentiate them?
Last edited by gregster on 08 Feb 2023, 21:21, edited 1 time in total.
Reason: Replaced topic title with smth more descriptive.

muggie23
Posts: 9
Joined: 08 Feb 2023, 21:14

Re: use 2 buttons with a small delay to target a specific window

Post by muggie23 » 08 Feb 2023, 21:34

forgot to mention I want it to repeat until the script is stopped

muggie23
Posts: 9
Joined: 08 Feb 2023, 21:14

Re: use 2 buttons with a small delay to target a specific window

Post by muggie23 » 08 Feb 2023, 22:18

hi I was able to get a loop running, i tried using window spy to use exe pid id to target a specific window, but it only targets the window that I am currently focused on.

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: use 2 buttons with a small delay to target a specific window

Post by off » 09 Feb 2023, 22:19

muggie23 wrote:
08 Feb 2023, 22:18
hi I was able to get a loop running, i tried using window spy to use exe pid id to target a specific window, but it only targets the window that I am currently focused on.
if the first and second window has the same Title, ahk_pid, and ahk_exe, ofcourse the script will only run at the currently focusing window, i suggest using Sandboxie which make different Title and pid from one application..

If the ahk_pid different, you can use ControlSend
example:

Code: Select all

ControlSend,, a, ahk_pid xxxx
ControlSend,, a, ahk_pid yyyy
you can also use WinSetTitle to differentiate same windows, and it only set the title to last active window
example:

Code: Select all

WinSetTitle, <original window title>,, <new window title>
tested to change 2 File Explorer with same title, ahk_class, and ahk_pid
and if this works, you can use:

Code: Select all

ControlSend,, a, Game Window 1 ; (original)
ControlSend,, a, Game Window 2 ; (WinSetTitle-ed)

User avatar
boiler
Posts: 16930
Joined: 21 Dec 2014, 02:44

Re: use 2 buttons with a small delay to target a specific window

Post by boiler » 09 Feb 2023, 22:33

off wrote: If the ahk_pid different, you can use ControlSend
example:

Code: Select all

ControlSend,, a, ahk_pid xxxx
ControlSend,, a, ahk_pid yyyy
You don’t want to hard-code in PID numbers because they change every time the application is run.

off wrote: you can also use WinSetTitle to differentiate same windows, and it only set the title to last active window
example:

Code: Select all

WinSetTitle, <original window title>,, <new window title>
tested to change 2 File Explorer with same title, ahk_class, and ahk_pid
and if this works, you can use:

Code: Select all

ControlSend,, a, Game Window 1 ; (original)
ControlSend,, a, Game Window 2 ; (WinSetTitle-ed)
Not only is this not recommended, there is no reason to do it. Once the windows are differentiated, ascertain the HWND (unique window ID) of each so you can refer to each by that using ahk_id. These also change with each incarnation of the window, so you wouldn’t hard-code the numbers in. You capture them in variables and refer to them using those variables.

muggie23
Posts: 9
Joined: 08 Feb 2023, 21:14

Re: use 2 buttons with a small delay to target a specific window

Post by muggie23 » 10 Feb 2023, 03:55

the scripts are working fine, but it does not work on a window that is unfocused.

User avatar
boiler
Posts: 16930
Joined: 21 Dec 2014, 02:44

Re: use 2 buttons with a small delay to target a specific window

Post by boiler » 10 Feb 2023, 07:20

muggie23 wrote: …it does not work on a window that is unfocused.
Some applications are like that and there’s not much that can be done about it.

Post Reply

Return to “Gaming Help (v1)”