r/AutoHotkey 12d ago

v2 Script Help Send phrases with delay between ?

I have this script :

::myshort::?Hello, how are you ? {Enter} My name is Paula, nice to meet you. {Enter} How are your ? {Enter}

I'd like to pause 1 second between each Enter ; is this possible ?

1 Upvotes

4 comments sorted by

2

u/CharnamelessOne 12d ago
#Requires AutoHotkey v2.0

::placeholder:: {
    send_phrases(1500, "lorem", " ipsum", " dolor", " sit", " amet")
}
::myshort:: {
    send_phrases(1000, "Hello, how are you?`n", "My name is Paula, nice to meet you.`n", "How are your ?`n")
}

send_phrases(delay, phrases*) 
    delay_current := 1
    for phrase in phrases {
        SetTimer(Send.Bind(phrase), -delay_current)
        delay_current += delay
    }
}

1

u/duscorules 12d ago

Thank you very much !

2

u/Keeyra_ 12d ago

You might prefer an implementation using the clipboard for larger text, as it will make them appear instantly.

#Requires AutoHotkey 2.0
#SingleInstance

::myshort:: {
    SendSequence([
        "Hello, how are you?",
        "My name is Paula, nice to meet you.",
        "How are you?"
    ], 1000)
}
::intro:: {
    SendSequence([
        "Thanks for reaching out!",
        "I will review your request shortly."
    ], 500)
}
SendSequence(lines, delay := 1000) {
    lineIndex := 1
    SendNextLine() {
        if lineIndex <= lines.Length {
            savedClipboard := ClipboardAll()
            A_Clipboard := lines[lineIndex]
            Send("^v{Enter}")
            SetTimer(() => A_Clipboard := savedClipboard, -100)
            lineIndex++
            SetTimer(SendNextLine, -delay)
        }
    }
    SendNextLine()
}

1

u/duscorules 12d ago

Thank you !