Skip to content

Instantly share code, notes, and snippets.

@JonathanStreet
Created January 28, 2019 22:57
Show Gist options
  • Save JonathanStreet/3c29718c1edca776e33a3ce93fbf6999 to your computer and use it in GitHub Desktop.
Save JonathanStreet/3c29718c1edca776e33a3ce93fbf6999 to your computer and use it in GitHub Desktop.
[AHK] Send text to multiple open windows (e.g. Notepad)
; Press `Ctrl + b` to start
^b::
InputBox, UserInput, Command, Enter a command.
if ErrorLevel
{
MsgBox, CANCEL was pressed.
}
else
{
; Find windows containing 'Notepad' anywhere.
SetTitleMatchMode, 2
WinGet, myList, list, Notepad
; Loop through all windows
Loop, %myList%
{
; Send the input & return to the window
WinGet MMX, MinMax, % "ahk_id" myList%a_index%
; Only run on windows that are visible
IfNotEqual MMX, -1
{
; Add a delay to the keys to prevent uppercase/lowercase issues
SetKeyDelay,,10
; Send the keystrokes to the window
ControlSend,, %UserInput%{return}, % "ahk_id" myList%a_index%
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment