How-to: Copy and paste multiple strings at the same time

Do you want to discover how to copy and paste text effectively?
copy and paste with multiple clipboards

This tutorial will show you how-to make a script that lets you copy and paste, then hold multiple strings.

Degree of difficulty:

Difficulty of the copy multiple strings with the clipboard how-to level 3
If you have never made a AutoHotkey script before i’ll show you the 5 fast steps.

Novice’s are recommend to have a look at this Tutorial

At the end of this post, I will put links for both a readymaded script and also a compiled exe for those who just want to try this little app.

Example video: (4:35)

How to make a script that can copy multiple strings

Before we start, all you need are 2 things:

and 16 lines of plain text from this how-to.

 

Now if you have AutoHotkey installed you can skip step one in this list.

How to create a new script:

  1. Download and install AutoHotkey.
  2. Right-click an empty spot on your desktop or in a folder of your choice.
  3. In the menu that appears, select New -> AutoHotkey Script.                 (Alternatively, select New -> Text Document.)
  4. Type a name for the file, ensuring that it ends in .ahk. For example: Testing.ahk
  5. Right-click the file and choose Edit Script.

Each script is a plain text file containing commands to be executed by AutoHotkey.exe

Lets get to the lines of code as this is a tutorial on how to make a script that can hold multiple copied strings and paste them back.

Comments

In AutoHotkey the ; is the character for comments by defult so everything after the ; does nothing.
Here the first two lines are just info to the user so we use the ; as it makes the lines comments, and the script will not use them.

;   ^     is short for using {ctrl}
;   +     is short for using {shift}

 

Copy and paste with hotkeys

Next we will setup a hotkey, Autohotkey comes build with the ability to easily make triggers like this, and it only takes one line of short code.

^1:: ; this is a hotkey = ctrl+1

 

Clipboard

Our hotkey rutines frist action will be to store the content of the clipboard, for this we will use a variable. We will call it “old_clip”.

old_clip := ClipboardAll

The above line will store any content (aka Clipboardall) from the clipboard in the variable “old_clip” which we can then use later to restore the content back to the clipboard.

Now we will clear the clipboard with the use of autohotkey’s build-in variable clipboard

Clipboard := ""

That line will clear any content on the clipboard but we have already stored that content so don’t worry.

 

Keyboard events

In the next line of script code, we will send the keyboard shotcut to copy the active selection.

Send, ^c ; (^ = ctrl) + c

The above line sends the key events {control down} then {c down} plus {c up} and then {control up} to the active window.

So now we will wait for the clipboard to hold data, this will be easy, if the clipboard is empty, and remember we did empty the clipboard above. So with this line we can wait for the keys we send, to copy the active selection in to the clipboard.

ClipWait, 2 ; wait for the empty clipboard to hold data

 

Okay now the clipboard holds the string that’s selected in the active window so lets store that copy in a new variable, we can call it “clip_one”.

clip_one := Clipboard

 

After that we then restore the old content back on the clipboard from the variable that we store at the start of this hotkey rutine

Clipboard := old_clip

 

Most! if not all, things must have an end, so to end this hotkey rutine we will use the “return” command

return

Wooden Clipboard to copy multiple strings

Okay I hope that was not way over your head! If so, I’d like to know in the comments please, and i’ll do my best to help you with your copy and paste needs.

Ready to write a rutine to paste back the copied string we just got stored in our variable?

 

Paste

Then for this we will again make a hotkey that we can use to paste our string back, how about using shift+1 for this?

+1:: ; this is a hotkey = shift+1

After that the frist thing we check is the content of our variable “clip_one”, for this we will use an IF condition statment that will tell us if something is true or false. Does that make sense to you?

Okay now if the variable is empty the IF statment will be true and the line right under it will be run, so here we will put a “return” command to put the script backin to a waiting stat (waiting for a new hotkey press). Because if our variable is empty we don’t need to paste anything and then there is no need to run anymore lines from this rutine and the return will help us do that.

if (clip_one = "") ; if the variable is empty
    return ; end this rutine

 

But if the variable holds data, the if statment will be false and script will skip the next line (the line below the if satament) and let the script proceed to the lines after, here we will put the content of our variable “clip_one” back on the clipboard, so we can use it with the normal windows pasting keys (ctrl+v).

But before we do all that, we frist store the existing content of the normal clipboard in the variable “old_clip” so we can restore the clipboard content back agian after we have pasted our string.

old_clip := ClipboardAll

 

Then we can set the stored string from our variable as the content of the clipboard so we can paste the string from the variable “clip_one” back.

clipboard := clip_one

 

So now the clipboard holds our string and we can send the windows keyboard shortcut for pasting.

Send, ^v ; (^ = ctrl) + v

 

After the paste is done, all we need to do is restore the old clipboard from our variable “old_clip”.

Clipboard := old_clip

 

Then we will also end this rutine with a return command

return

 

So now we have a way to:

  • Copy
  • hold
  • paste

Now we can save the script and also run it by double clicking the file as this will copy and paste just fine but lets wait.

 

Next up: How to make it hold multiple strings!

copy multiple Clipboards

 

Multiple

Now we do just about the same thing for all the number of strings we’d like to be able to copy and paste at any given time.

We will start with setting up a new hotkey as the start of a new rutine, this time we will use ctrl+2 just to keep it consistent (any other hotkey can be setup)

^2::

 

This rutine will also start with the “save the clipboard in a variable” part os we can restore it later.

old_clip := ClipboardAll

 

We remember to clear the clipboard, so later we can wait for it to hold data, to do this we store a blank string aka nothing in the clipboard.

Clipboard := ""

 

Then the sending of the keyboard events

Send ^c          ; ctrl+c to copy the active selection

 

Now we wait for the string to by on the clipboard

clipwait, 2         ; max 2 seconds wait

 

Time to store the new content of the clipboard in our variable this time we will call it “clip_two”.

Clip_two := Clipboard

 

Now we restore the clipboard back.

clipboard := old_clip

 

And done.

return

 

Next we make one more pasting rutine.

+2::        ; (shift+2)

 

This rutine will also start by making sure we have stored something in our variable “clip_two”.

if (clip_two = "") ; if the variable is blank or not set, return
    return

 

Okay ones agian we store the clipboarall data.

old_clip := ClipboardAll

 

Now we put our variable in the clipboard so we can paste it.

clipboard := clip_two

 

And then we send the key events to paste it.

Send, ^v      ; ( ctrl+v )

 

Lets restore the old clipboard.

clipboard := old_clip

 

End it with a return.

return

Thats about it, now you can just keep going until you have the number of clipboards you need for copy and pasting and you don’t even need to use numbers as the hotkeys or ctrl and shift.

Anything I missed or does this kind of post even help you out?

If you have any Questions you can always use the comments or contact page

Try it

To use your new script, continue as follows:

  1. Save and close the file.
  2. Double-click the file to launch it. A new icon appears in the taskbar notification area.
  3. Select some text then hold down the CTRL key and press 1. Now you can paste that text back out with SHIFT+1.
  4. To exit or edit the script, right-click the green “H” icon in the taskbar notification area.

Notes:

  • Multiple scripts can be running simultaneously, each with its own icon in the taskbar notification area.
  • Each script can have multiple hotkeys and hotstrings.
  • To have a script launch automatically when you start your computer, create a shortcut in the Start Menu’s Startup folder.

 

Downloads:

 

 

7 Comments

  1. The video absolutely SUCKED. Too small to follow then out of focus when expanded. The VERY FIRST CLICK cant be followed because it doesn’t show where to begin. Christ, I hate people like this !

    1. Sad you feel that way, but thank you for the feedback…

  2. Thanks ,a really good tutorial. By breaking down and explaining each step like you did makes all the difference.
    Eoghan

  3. Useful suggestions . I loved the info , Does someone know if my business could locate a template AR DFA Bill of Sale form to complete ?

  4. Couldn’t you avoid the multiple lines of code on the pasting command by simply telling ahk to Send the variable?

    +2::
    Send, %clip_2%
    Return

    in my experience, checking to make sure something is stored in the variable isn’t necessary either because if there’s nothing stored in the variable, nothing happens when you invoke the hotkey.

    1. yes you can avoid it that way, but if you have copied a lot of text, “pasting it” will be a lot faster 🙂

      The checking is there to not mess with the clipboard if we don’t need to…

  5. […] Nice way to remove any form of formating for the content of your clipboard for more ways to use the clipboard see How to make a script that can copy multiple strings […]

Leave a Reply