chatautohotkey

How to send a block of text line-by-line in a hotstring, and be able to review each line when it's sent?


I have a block of text containing multiple lines and want to send it to a chap app line-by-line. I want to have a procedure like this:

  1. I type in a hotstring trigger (say, hotstringtrigger), and AutoHotKey will send the first line (the text should stay in the input box of chat app)
  2. I edit it to suit my need
  3. I press Enter. The chat app will send the text, and AutoHotKey will send the next line
  4. Return to 2 until no more line is left
  5. Enter will act normal after that, until hotstringtrigger is typed again

So far, my attempt is to split it into multiple hotstrings:

:*:hotstringtrigger::first line
:*:hotstringtrigger2::second line
:*:hotstringtrigger3::third line
...

But this has some disadvantages:

This page doesn't seem to cover this: Hotstrings - Definition & Usage | AutoHotkey


Solution

  • I guess very simple and straight forward example could be something like this

    TextToSend := "
    (
    first line
    second line 
    )"
     
    lines := StrSplit(TextToSend, "`n", "`r")
     
     
    :*T:hotstringtrigger::
        SendInput,
        (
        Hello ____________________. Welcome to the World^{Home}{right 6}
        )
        
        i := 1
    return
     
    ~Enter::
        if (!i || i > lines.length())
            return
        
        SendInput, % "{Text}" lines[i]
        i++
    return
    

    The input text is here simply typed into a continuation section and loaded from there to an array when the script starts. When your desired hotstring is ran, the index i gets reset.

    Then upon pressing Enter, text is sent from the array until our index, i, is greater than the length of lines in the input string.

    If your input text has very long lines, you should load the lines to your clipboard first, and then just send Ctrl + v.