Clipboard and line breaks Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
assarj
Posts: 3
Joined: 18 Nov 2023, 07:26

Clipboard and line breaks

Post by assarj » 18 Nov 2023, 08:01

Hi AHK Community, I'm trying to create a script in AHK 2, but I don't understand why it's not working. Initially, it should work like this:

Trigger: bbb

Replace with the text:
Thanks for your letter!

{text from clipboard}

Best regards,
our team
I found that to insert text from the clipboard, you need to use:

Code: Select all

{
SendInput "{Raw}" A_Clipboard
}

But how to integrate this with the text and include line breaks, I have no idea. The AI doesn't provide any helpful advice either.

Can someone please help me solve this riddle?

User avatar
DuckingQuack
Posts: 221
Joined: 20 Jan 2023, 18:20

Re: Clipboard and line breaks

Post by DuckingQuack » 18 Nov 2023, 08:20

I think you were closer to answering your own riddle than you thought.
https://www.autohotkey.com/docs/v2/Hotstrings.htm
After typing "bbb", once you hit space or enter, it is replaced with the text from the clipboard.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
Esc::ExitApp

::bbb::{
    SendInput "{Raw}" A_Clipboard
}
Best of Luck,
The Duck

assarj
Posts: 3
Joined: 18 Nov 2023, 07:26

Re: Clipboard and line breaks

Post by assarj » 18 Nov 2023, 08:54

@DuckingQuack Yes, if I do it I just enter my clipboard. But I need to insert clipboard into other text

In the end it should look like this
Thanks for your letter!

{text from my clipboard}

Best regards,
our team
So after triggering bbb I expect to get:

Code: Select all

text "Thanks for your letter!"
Then 1 empty line
Text from my clipboard
One more empty line
On the new line text "Best regards,"
And on the new line text "our team"
I can get this using typinator, and suppose Autohotkey has some similar features, but I don't know how to do it

I know how to trigger text or trigger clipboard, but how to combine them together as I described above I don't know

assarj
Posts: 3
Joined: 18 Nov 2023, 07:26

Re: Clipboard and line breaks  Topic is solved

Post by assarj » 18 Nov 2023, 09:42

I received a solution on Discord from the user Descolada, and I'm very grateful to him.

In case someone needs it in the future:

Code: Select all

#Requires AutoHotkey v2

:X:bbb::SendText("Thanks for your letter!`n`n" A_Clipboard "`n`nBest regards,`nour team")
You can modify this code to run automatically without a space (by adding an asterisk *) and also add additional lines by including `n

User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: Clipboard and line breaks

Post by andymbody » 18 Nov 2023, 09:44

Like this?

Code: Select all

::bbb::
{
SendInput "{Raw}Thanks for your letter!`n`n" A_Clipboard "`n`nBest regards,`nout team"
}
Last edited by andymbody on 18 Nov 2023, 09:56, edited 1 time in total.

User avatar
DuckingQuack
Posts: 221
Joined: 20 Jan 2023, 18:20

Re: Clipboard and line breaks

Post by DuckingQuack » 18 Nov 2023, 09:47

Alright, then I guess you wanted to know about escape sequences.

https://www.autohotkey.com/docs/v2/misc/EscapeChar.htm

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
InstallMouseHook
InstallKeybdHook
Esc::ExitApp

::bbb::{
    SendInput "`n{Raw}" A_Clipboard "`n"
}
Best of Luck,
The Duck

Post Reply

Return to “Ask for Help (v2)”