Sending keystrokes to multiple windows

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CTSS
Posts: 3
Joined: 26 Aug 2021, 19:32

Sending keystrokes to multiple windows

19 Oct 2021, 13:32

I’m trying to send the keyboard strokes Ctrl + Alt + J to all open Google Chrome windows.
Ctrl + Alt + J needs to be held down at the same time.

I want to be able to hold down a key, for example q, and have it hold down Ctrl + Alt + J in all open Google Chrome windows.

All I’ve been able to figured out so far is the below code, but it doesn’t hold all three, it sends the letter j:

Code: Select all

q::
ControlSend,, ^!j, Google Chrome
return
When I am using this code and have Google Chrome open as the active window this works:

Code: Select all


q::
Send, ^!j
return
Can someone please help me with this?
User avatar
mikeyww
Posts: 26854
Joined: 09 Sep 2014, 18:38

Re: Sending keystrokes to multiple windows

19 Oct 2021, 16:39

You could activate each window before sending the keys to it.
CTSS
Posts: 3
Joined: 26 Aug 2021, 19:32

Re: Sending keystrokes to multiple windows

20 Oct 2021, 01:15

mikeyww wrote:
19 Oct 2021, 16:39
You could activate each window before sending the keys to it.
Would you be able to please help me with this?

Will it still hold down the keys simultaneously in all windows?
User avatar
mikeyww
Posts: 26854
Joined: 09 Sep 2014, 18:38

Re: Sending keystrokes to multiple windows

20 Oct 2021, 05:48

To hold a key down, you would issue a "down" action, such as Send {j down}, or Send {Ctrl down}{Alt down}{j down}. In a test, you can try this in two windows, so see whether it works. To my knowledge, one cannot hold keys down in different windows at the same time, but you could test it. I sometimes think of AHK as doing what a person could do-- and you could not do this yourself-- though I know that AHK can also do a variety of additional things. In any case, KeyHistory can show you what is happening with the keys during your testing.
CTSS
Posts: 3
Joined: 26 Aug 2021, 19:32

Re: Sending keystrokes to multiple windows

20 Oct 2021, 10:26

mikeyww wrote:
20 Oct 2021, 05:48
To hold a key down, you would issue a "down" action, such as Send {j down}, or Send {Ctrl down}{Alt down}{j down}. In a test, you can try this in two windows, so see whether it works. To my knowledge, one cannot hold keys down in different windows at the same time, but you could test it. I sometimes think of AHK as doing what a person could do-- and you could not do this yourself-- though I know that AHK can also do a variety of additional things. In any case, KeyHistory can show you what is happening with the keys during your testing.
Instead of holding Ctrl + Alt + J, can I press it repeatedly? It needs to be held all 3 same as Ctrl + Alt + Del but and be released and immediately repressed.
If I can’t send to all windows at once, am I able to send them to each window, something like 1ms apart from each other?
User avatar
mikeyww
Posts: 26854
Joined: 09 Sep 2014, 18:38

Re: Sending keystrokes to multiple windows

20 Oct 2021, 11:40

Code: Select all

F3::
WinGet, chrome, List, ahk_exe chrome.exe
Loop, %chrome% {
 WinActivate, % "ahk_id " chrome%A_Index%
 Send ^!j
}
Return
You can insert another :arrow: Loop at any point, to repeat the send.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Giresharu, Google [Bot], inseption86, KruschenZ, mikeyww, Swiftly9767 and 291 guests