Send Text to Tagged Edit Windows

Helpful script writing tricks and HowTo's
User avatar
Posts: 122
Joined: 01 Aug 2016, 18:17

Send Text to Tagged Edit Windows

Post by jackdunning » 29 Apr 2020, 15:09

Initially, I thought that I would post this in the Scripts and Functions forum, but decided that this window tagging script acts more as a technique than a standalone script. While I offer a couple of uses for setting up target windows (collecting reference text and quick testing AutoHotkey code), others may see many more.

The CopyRefTagWin.ahk script copies text to a pre-targeted Notepad, WordPad, or GUI Edit window. To tag a reference target window, mark either a NotePad, WordPad, or GUI Edit field as the target by activating the window, clicking in the target field, and pressing Ctrl+Win+Alt+T. Then move to any source window, highlight the targeted text, and press Ctrl+Alt+C.

I offer more specific how-to information in "Tricks for Tracking and Activating Target Process Windows" and "Channeling Text to a Tagged Window."


Note: While I originally used the technique to collect reference data from multiple sources without the tedious window hopping, CopyRefTagWin.ahk works equally as well for testing AutoHotkey code using GeekDude's AutoHotkey CodeQuickTester. (I discuss this tool in “Save Time with CodeQuickTester for Testing and Modifying Scripts.”)

CopyRefTagWin.ahk Code:

Code: Select all

   If !WinTag
      MsgBox, Tag a target window in NotePad
                  ,`rWordPad or a GUI edit field:`r`r     1
                  . Activate window`n     2
                  . Press Ctrl+Win+Alt+T

    OldClipboard := ClipboardAll
    Clipboard := ""     ;clears the Clipboard
    SendInput, ^c
    ClipWait 0 ; pause for Clipboard data
    If ErrorLevel
      MsgBox, No text selected!
   Control, EditPaste, %Clipboard% `n`n ,%control%,  ahk_id %WinTag%
;   To replace text (rather than add), use the following ControlSetText command:
;   ControlSetText , %Control%, %Clipboard%, ahk_id %WinTag%
   ToolTip , Text inserted into %WinTitle%`rControl: %control%!
   Sleep, 3000
   Clipboard := OldClipboard

   Click, %A_CaretX%, %A_CaretY%
   MouseGetPos, , , WinTag, Control
   WinGetTitle, WinTitle, ahk_id %WinTag%
   MsgBox The "%WinTitle%" window is tagged!`rUnique ID: %WinTag%`rControl: %Control%`rCtrl+Win+Alt+R to activate.

   WinActivate, ahk_id %WinTag%
The CopyRefTagWin.ahk script offers three distinct functions:
  1. Tag the window to receive text (Ctrl+Win+Alt+T). Must activate the window first.
  2. Copy text from any other app directly into the tagged window by selecting the desired text and executing the Ctrl+Alt+C Hotkey combination.
  3. Return to the tagged window (Ctrl+Win+Alt+R) to process text or, as in the case of a tagged “CodeQuickTest” window, run the copied code.
Without activating the target window, the script uses the Control, EditPaste command to insert the text into the window at the cursor location. Uncomment the ControlSetText command in the script to replace rather than add text.

Use Ctrl+Win+Alt+R to return to the tagged window.

Return to “Tutorials”