1
votes

I have been working on a little AHK script to give myself a larger clipboard when copy-pasting. So far I have the following:

global bigboard := {}

^+c::copyToClipboard()
^+v::pasteFromClipboard()


copyToClipboard() {
    Input, num, L1 T10
    if (ErrorLevel = Timeout or RegExMatch(num, "[0-9]") = 0) { 
        return
    }
    oldC := ClipboardAll
    Send, ^c
    bigboard[num] := ClipboardAll
    Clipboard := oldC
    oldC =
    return
}

pasteFromClipboard() {
    Input, num, L1 T10
    if (ErrorLevel = Timeout or RegExMatch(num, "[0-9]") = 0) { 
        return
    }
    oldC := ClipboardAll
    Clipboard := bigboard[num]
    Send, ^v
    Clipboard := oldC
    oldC =
    return
}

Yes, there's some repeated code here and it could certainly be a lot more organized, but this isn't exactly enterprise stuff. Anyways, this isn't working. After a good deal of debugging, It seems that the script properly copies data when given valid input [ctrl+shift+c followed by any number], but when I try to paste it back out it simply does nothing. On top of that, the clipboard contents are properly stored and restored between uses of the copy-paste functionality, so it's apparently nothing to do with the clipboard interaction, just something about how I'm using the object to store data. I have also tried using

bigboard[%num%]

in case it needed the value from num, but that didn't work either. Any help would be appreciated.

2

2 Answers

0
votes

There are only two methods of storing clipboard contents:

  1. in a simple variable
  2. in a file

You cannot store clipboard contents in an object or array

Here is a method for storing multiple clipboards that might help.

0
votes

Give the clipboard some time to receive the data by adding a Sleep or Clipwait, like so

pasteFromClipboard() {
    Input, num, L1 T10
    if (ErrorLevel = Timeout or RegExMatch(num, "[0-9]") = 0) { 
        return
    }
    oldC := ClipboardAll
    Clipboard:="" ; empty it, might help, probably not needed
    Clipboard := bigboard[num]
    Sleep 100 ; or 200-300 or try the ClipWait command to give the clipboard some time to receive the data
    Send, ^v
    Clipboard := oldC
    oldC =
    return
}