Send Text to Tagged Edit Windows

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

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

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.

FCALIZZ
Posts: 7
Joined: 23 Jun 2023, 12:17

Re: Send Text to Tagged Edit Windows

Post by FCALIZZ » 26 Jun 2023, 16:11

@jackdunning thank you very much, as a researcher this tool is unvaluable for quick sending some paragraphs to your notepad. however it's not working for me with online or browser text editors, i tried by tagging a google docs tab, and also an onlinenotepad.org tab (both as standalone separate windows or as tabs with other sister tabs in the window) so i can send the contents to them by pressing Ctrl + Alt + C. When pressed, the messagebox pops up with the title and url of the source, with its Yes/No buttons. i press yes or no, and then the confirmation tooltip appears, but the destination tab (google docs or onlinenotepad.org) remains unchanged.

I tried this script by tagging a local word document or a notepad and taking as a source a pdf book or a webpage, and in these cases it works flawlessly. the problem as mentioned above is when the destination or tag is an online editing tool.
I'm using brave browser but also tried using google chrome.

Post Reply

Return to “Tutorials (v1)”