Send Text to Tagged Edit Windows

Helpful script writing tricks and HowTo's
User avatar
jackdunning
Posts: 118
Joined: 01 Aug 2016, 18:17
Facebook: https://www.facebook.com/ComputorEdgeEBooks/posts
Contact:

Send Text to Tagged Edit Windows

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."

Image

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

^!c::
   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
      Return
   }

    OldClipboard := ClipboardAll
    Clipboard := ""     ;clears the Clipboard
    SendInput, ^c
    ClipWait 0 ; pause for Clipboard data
    If ErrorLevel
    {
      MsgBox, No text selected!
      Return
    }
   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
   ToolTip
   Clipboard := OldClipboard
Return

^!#t::
   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.
Return


^!#r::
   WinActivate, ahk_id %WinTag%
Return
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”

Who is online

Users browsing this forum: No registered users and 5 guests