Trouble with Multiple Copy/Paste Function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jcvinci
Posts: 3
Joined: 13 Dec 2017, 15:43

Trouble with Multiple Copy/Paste Function

13 Dec 2017, 16:10

I'm trying to write a function that will allow me to have multiple, separate clipboards that I can copy and paste to and from.

Below is my attempt at that function. But when I go to paste what has been (presumably) copied I get an error that states:
Warning: This variable has not been assigned a value.

Specifically: ClipboardData3 (a global variable)
[and then it points to my line 352 (in PasteRoutine) which says" Clipboard := ClipboardData%PasteID%"]

Any suggestions would be appreciated.

Thank you,

John Vinci

Code: Select all

;######################################################
; Copy/Paste Functions
;######################################################
global ClipboardData1 = , ClipboardData2 = , ClipboardData3 = 


CopyRoutine(CopyID)
{
	global 
	local oldClipboard := ClipboardAll	; Save current clipboard to variable
	Send ^c								; Copy text into Clipboard
	ClipWait 2							; wait for it to be copied
	if ErrorLevel
	{
		Clipboard := oldClipboard
	}
	ClipboardData%CopyID% := ClipboardAll	;
	Clipboard := oldClipboard
	oldClipboard =  
}
PasteRoutine(PasteID)
{
	global
	local oldClipboard := ClipboardAll
	Clipboard := ClipboardData%PasteID%
	Send ^v							; Paste Text
	
	Clipboard := oldClipboard
	oldClipboard =  
}

<#<^1:: CopyRoutine(1)
<#<^2:: CopyRoutine(2)
<#<^3:: CopyRoutine(3)

<#<^4:: PasteRoutine(1)
<#<^5:: PasteRoutine(2)
<#<^6:: PasteRoutine(3)
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Trouble with Multiple Copy/Paste Function

13 Dec 2017, 16:57

Your code seems to work great for me. LCtrl+LWin+3 copies to the 3rd clipboard and LCtrl+LWin+6 pastes it correctly and without error. Perhaps you weren't pressing LCtrl+LWin+3 when you thought that you were...?
jcvinci
Posts: 3
Joined: 13 Dec 2017, 15:43

Re: Trouble with Multiple Copy/Paste Function

13 Dec 2017, 19:22

So it does. Thank you. I was programming a macro keyboard made by Genovation and it must not have been entering the keystrokes correctly.
jcvinci
Posts: 3
Joined: 13 Dec 2017, 15:43

Re: Trouble with Multiple Copy/Paste Function

09 Mar 2018, 17:09

OK so I'm still having trouble with this script. It's not very consistent. Here's what's happening

First I'll copy "Original Text in Clipboard" by selecting it from Notepad++ and clicking Ctrl-c
Then I copy "Line 1" from notepad using windows-ctrl-1 (<#<^1)
Then I copy "Line 2" from notepad using windows-ctrl-2 (<#<^2)
Then I copy "Line 3" from notepad using windows-ctrl-3 (<#<^3)

Now I'm going to paste then all into Notepad++, by clicking doing the following commands:

Ctrl-v
windows-ctrl-4
windows-ctrl-5
windows-ctrl-6

I get what I expect to get:
Original Text in Clipboard
Line 1
Line 2
Line 3
It works just the same in regular Notepad.

But now let me try to use those same commands to paste into Microsoft Word. Here's what I get:
Original Text in Clipboard
Original Text in Clipboard
Original Text in Clipboard
Original Text in Clipboard
When I try to use the commands to change the name of a folder in Windows Explorer, It behaves the same way as Microsoft Word. It only pastes "Original Text in Clipboard." (Oddly enough it'll work every now and then but I can't figure out why nor can I reproduce it.)

Does anyone else get this same behavior?
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Trouble with Multiple Copy/Paste Function

17 Mar 2018, 17:19

Try modifying the parameters of ClipWait. For example, try ClipWait, 2, 1. That's my only idea at the moment.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Trouble with Multiple Copy/Paste Function

17 Mar 2018, 18:49

jcvinci, I get the same results you do with Word. Haven't found a fix yet, either.
Regards,
burque505
gorksmash
Posts: 1
Joined: 16 Dec 2021, 11:13

Re: Trouble with Multiple Copy/Paste Function

16 Dec 2021, 11:17

I had the same issue, my workaround is to add in some sleep timers and it performs as expected. your timers may vary for your PC but this worked for me without the issue listed above.

Code: Select all

#Persistent
#InstallKeybdHook
SendMode Input

; Hotkeys
^1::Copy(1)
!1::Paste(1)

^2::Copy(2)
!2::Paste(2)

^3::Copy(3)
!3::Paste(3)

Copy(clipboardID)
{
	global ; All variables are global by default
	local oldClipboard := ClipboardAll ; Save the (real) clipboard
	
	Clipboard := "" ; Erase the clipboard first, or else ClipWait does nothing
	sleep, 20
	Send, ^c
	sleep, 20
	ClipWait, 2, 1 ; Wait 1s until the clipboard contains any kind of data
	if ErrorLevel 
	{
		Clipboard := oldClipboard ; Restore old (real) clipboard
		return
	}
	
	ClipboardData%clipboardID% := ClipboardAll
	
	Clipboard := oldClipboard ; Restore old (real) clipboard
}

Cut(clipboardID)
{
	global ; All variables are global by default
	local oldClipboard := ClipboardAll ; Save the (real) clipboard
	
	Clipboard := "" ; Erase the clipboard first, or else ClipWait does nothing
	Send ^x
	ClipWait, 2, 1 ; Wait 1s until the clipboard contains any kind of data
	if ErrorLevel 
	{
		Clipboard := oldClipboard ; Restore old (real) clipboard
		return
	}
	ClipboardData%clipboardID% := ClipboardAll
	
	Clipboard := oldClipboard ; Restore old (real) clipboard
}

Paste(clipboardID)
{
	global
	local oldClipboard := ClipboardAll ; Save the (real) clipboard
	Clipboard := ""
	Clipboard := ClipboardData%clipboardID%
	sleep, 40
	ClipWait, 2, 1
	Send, ^v
	sleep, 20
	Clipboard := oldClipboard ; Restore old (real) clipboard
	oldClipboard := "" 
}
User avatar
rommmcek
Posts: 1478
Joined: 15 Aug 2014, 15:18

Re: Trouble with Multiple Copy/Paste Function

16 Dec 2021, 13:43

Improved, but not tested gorksmash's version.
Spoiler
bye!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], niCode, Rohwedder and 112 guests