Adding new lines to Hotstrings

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CuriousDad
Posts: 75
Joined: 21 Mar 2023, 11:23

Adding new lines to Hotstrings

06 Apr 2024, 16:55

Hello. I would like to create a hot string that will automatically type short sentences with each sentence starting on a new line. For instance:

The quick brown fox.
Jumped over the lazy dog.

In creating a hot string, I noticed the following code created a stall in printing the text:

Code: Select all

:C:tst::
(
The quick brown fox.
Jumped over the lazy dog.
)
return
I received help for hot strings previously and tried something that was suggested:

Code: Select all

testing :=
(
The quick brown fox.
Jumped over the lazy dog.
)

:C:tst::
Clipboard := testing
Send ^v
return
However, that attempt ended with an error. Besides referring to another file (such as a text file or Word file), is there a way to incorporate multiple short sentences in a hot string output within the AHK file? The example I gave is a short one. I would like to incorporate one with 30 or 40 short lines. Thanks.
User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Adding new lines to Hotstrings

06 Apr 2024, 21:32

:= is always followed by an expression. The documentation includes pages about expressions, with more details.

Code: Select all

#Requires AutoHotkey v1.1.33.11

:C:tst::
Clipboard := ""
Clipboard := "
(
The quick brown fox.
Jumped over the lazy dog.
)"
ClipWait 0
If ErrorLevel
 MsgBox 48, Error, An error occurred while waiting for the clipboard.
Else Send ^v
Return
CuriousDad
Posts: 75
Joined: 21 Mar 2023, 11:23

Re: Adding new lines to Hotstrings

07 Apr 2024, 02:01

Thank you. I'll look into expressions.
CuriousDad
Posts: 75
Joined: 21 Mar 2023, 11:23

Re: Adding new lines to Hotstrings

14 May 2024, 23:13

I looked into Expressions and didn't understand any of it. Thank you nonetheless for your help.

I was wondering if there was a way to simulate typing the information in rather than copying and pasting. I am using it for a program and I use Word to copy and paste, but I thought it would be faster to use hotstrings. However, the program I now use does not allow copying and pasting more than a certain number of characters, but will allow input such as typing and dictation to extend beyond the character limitation for pasting.
User avatar
CoffeeChaton
Posts: 35
Joined: 11 May 2024, 10:50

Re: Adding new lines to Hotstrings

14 May 2024, 23:55

Code: Select all

#Requires AutoHotkey v1.1.33.11

:Cx:tst::tstfn() ; x-flag https://www.autohotkey.com/docs/v1/Hotstrings.htm#X

tstfn() {
    _ClipSaved := ClipboardAll


    Clipboard := ""
    longStr := "
(
The quick brown fox.
Jumped over the lazy dog.
)"

    arr := StrSplit(longStr, "`n") ; Split with newline character

    For _i, text in arr {
        Clipboard := text "`n"
        ClipWait, 0
        If ErrorLevel
            MsgBox, 48, Error, % "An error occurred while waiting for the clipboard."
        Else Send, ^v
        Sleep, 10 ; 10ms
    }


    Clipboard := _ClipSaved
}
Just paste it in multiple times

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 109 guests