Sending blocks of text with line breaks and spacing Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Thomasta3
Posts: 6
Joined: 06 Dec 2023, 12:31

Sending blocks of text with line breaks and spacing

Post by Thomasta3 » 06 Dec 2023, 12:46

Hi,

I am trying to make a script which will write out what I paste into it, however any line breaks from the copied text break the script.

For example I want the following text to be written out (example from a random wikipedia page):

"A wrench or spanner is a tool used to provide grip and mechanical advantage in applying torque to turn objects—usually rotary fasteners, such as nuts and bolts—or keep them from turning.

In the UK, Ireland, Australia, and New Zealand spanner is the standard term. The most common shapes are called open-ended spanner and ring spanner. The term wrench is generally used for tools that turn non-fastening devices (e.g. tap wrench and pipe wrench), or may be used for a monkey wrench—an adjustable pipe wrench.[1] "


Using the following script:

Code: Select all

#n::
send, A wrench or spanner is a tool used to provide grip and mechanical advantage in applying torque to turn objects—usually rotary fasteners, such as nuts and bolts—or keep them from turning.

In the UK, Ireland, Australia, and New Zealand spanner is the standard term. The most common shapes are called open-ended spanner and ring spanner. The term wrench is generally used for tools that turn non-fastening devices (e.g. tap wrench and pipe wrench), or may be used for a monkey wrench—an adjustable pipe wrench.[1]
return
Will give an error due to the spacing between the two paragraphs.

Changing the script to

Code: Select all

#n::
send, A wrench or spanner is a tool used to provide grip and mechanical advantage in applying torque to turn objects—usually rotary fasteners, such as nuts and bolts—or keep them from turning. In the UK, Ireland, Australia, and New Zealand spanner is the standard term. The most common shapes are called open-ended spanner and ring spanner. The term wrench is generally used for tools that turn non-fastening devices (e.g. tap wrench and pipe wrench), or may be used for a monkey wrench—an adjustable pipe wrench.[1]
return
Gives the functionality I want, however not replicating the formatting and there's an extra step to format the text first.

The actual use case has a lot more spacings, so if there's a way to take the raw copied text with formatting and send it replicating the formatting that would be great.

Thanks in advance!

[Mod edit: [code][/code] tags added. Please use them yourself when posting code!]

User avatar
JoeWinograd
Posts: 2219
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Sending blocks of text with line breaks and spacing  Topic is solved

Post by JoeWinograd » 06 Dec 2023, 13:16

Hi @Thomasta3,
I see that this is your first post here, so let me start with...Welcome Aboard!

Try this:

Code: Select all

#n::
send,
(
A wrench or spanner is a tool used to provide grip and mechanical advantage in applying torque to turn objects—usually rotary fasteners, such as nuts and bolts—or keep them from turning.

In the UK, Ireland, Australia, and New Zealand spanner is the standard term. The most common shapes are called open-ended spanner and ring spanner. The term wrench is generally used for tools that turn non-fastening devices (e.g. tap wrench and pipe wrench), or may be used for a monkey wrench—an adjustable pipe wrench.[1]
)
return
Regards, Joe

RussF
Posts: 1377
Joined: 05 Aug 2021, 06:36

Re: Sending blocks of text with line breaks and spacing

Post by RussF » 06 Dec 2023, 13:21

As I was preparing a reply, I see that Joe got in ahead of me, so I will just add that the documentation for line continuation can be found here.

Russ

User avatar
JoeWinograd
Posts: 2219
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Sending blocks of text with line breaks and spacing

Post by JoeWinograd » 06 Dec 2023, 13:37

Hey Russ,
Excellent addition! I was negligent in not pointing to the doc. Thanks, Joe

Thomasta3
Posts: 6
Joined: 06 Dec 2023, 12:31

Re: Sending blocks of text with line breaks and spacing

Post by Thomasta3 » 06 Dec 2023, 15:19

Thank you so much @JoeWinograd and @RussF for the quick replies and warm welcome! :D

It works great.

Thomasta3
Posts: 6
Joined: 06 Dec 2023, 12:31

Re: Sending blocks of text with line breaks and spacing

Post by Thomasta3 » 06 Dec 2023, 15:23

Was there a way to add the ability to pause/resume the script with a hotkey? I feel that could be quite useful, say for instance with the letter P.

Thomasta3
Posts: 6
Joined: 06 Dec 2023, 12:31

Re: Sending blocks of text with line breaks and spacing

Post by Thomasta3 » 06 Dec 2023, 15:29

Thomasta3 wrote:
06 Dec 2023, 15:23
Was there a way to add the ability to pause/resume the script with a hotkey? I feel that could be quite useful, say for instance with the letter P.
Sorry I meant to add more to this reply.

I've tried to add the lines:

Code: Select all

Pause::Pause  ; The Pause/Break key.
#p::Pause  ; Win+P
[Mod edit: + [code][/code] tags.]

Per the Pause function page but it doesn't seem to work.

RussF
Posts: 1377
Joined: 05 Aug 2021, 06:36

Re: Sending blocks of text with line breaks and spacing

Post by RussF » 06 Dec 2023, 15:51

I don't know what the rest (if any) of your script looks like, but the script is essentially paused until you press the hotkey. Pause does not pause hotkeys, Suspend does. I would suggest reading all the documentation regarding both.

Russ

Post Reply

Return to “Ask for Help (v1)”