Search code examples
saveclipboardautohotkey

AutoHotkey extend clipboard


as we all experienced one time or more, it sometimes is really annoying to have to replace your clipboard-content with other content (while you only need the other information once or so).

I thought we could solve this problem using autohotkey, but I have no clue how to.

I'm thinking about setting variables in a hotkey, like when you press CtrlC, the old clipboard-content gets stored inside AutoHotkey, and you could retrieve that old content by pressing i.e. AltV, while the normal CtrlV just returns the current value of the clipboard.

Could anyone help me with this please? I don't know how to permanently store values inside AutoHotkey.

Regards, Aart


EDIT:

I have found the perfect script. I modified it as I wanted it to work. You can now just use Ctrl+C and carry on copying, but if you want to retrieve something, just use AltLeftArrow and it's there! Have fun with it; I know I will. :)

Controls:

  • Ctrl+C >> copy
  • Alt+V >> paste
  • Alt+Left Arrow >> cycle back
  • Alt+Right Arrow >> cycle forward
  • Alt+H >> display this message

Code:

handleClip(action)
{
   global static AddNextNum
   global static GetNextNum
   global static HighestNum
   global static ClipArray
   global static ClipArray1
   global static ClipArray2
   global static ClipArray3
   global static ClipArray4
   global static ClipArray5
   global static ClipArray6
   global static ClipArray7
   global static ClipArray8
   global static ClipArray9
   global static ClipArray10
   global static ClipArray11
   global static ClipArray12
   global static ClipArray13
   global static ClipArray14
   global static ClipArray15
   global static ClipArray16
   global static ClipArray17
   global static ClipArray18
   global static ClipArray19
   global static ClipArray20
   global static ClipArray21
   global static ClipArray22
   global static ClipArray23
   global static ClipArray24
   global static ClipArray25
   global static ClipArray26
   global static ClipArray27
   global static ClipArray28
   global static ClipArray29
   global static ClipArray30

   if (action = "save")
   {
      if (AddNextNum < 30)
      {
         AddNextNum += 1 ;
      }
      else
      {
         AddNextNum := 1 ;
      }


      if (HighestNum < 30)
      {
         HighestNum += 1 ;
      }

      GetNextNum := AddNextNum ;   
      ClipArray%AddNextNum% := Clipboard
   }
   else if ((action = "get") OR (action = "roll"))
   {
      if (GetNextNum != 0)
      {
         if (action = "roll")
         {
            Send, ^z
         }
         Clipboard := ClipArray%GetNextNum%
         if (GetNextNum > 1)
         {
            GetNextNum -= 1 ;
         }
         else
         {
            GetNextNum := HighestNum
         }
         Send, ^v
      }
   }
   else if (action = "rollforward")
   {
      if (GetNextNum != 0)
      {
         Send, ^z
         if (GetNextNum < HighestNum)
         {
            GetNextNum += 1 ;
         }
         else
         {
            GetNextNum := 1
         }
         Clipboard := ClipArray%GetNextNum%
         Send, ^v
      }
   }
   else if (action = "clear")
   {

      GetNextNum := 0
      AddNextNum := 0
      HighestNum := 0
   }
}

!0::
   handleClip("clear")
return

^c::
   suspend on
   Send, ^c
   suspend off
   handleClip("save")

return

!v::
   handleClip("get")
return

!Left::
   handleClip("roll")
return

!Right::
   handleClip("rollforward")
return

!H::
MsgBox Extended Clipboard controls: `r`n`r`nCtrl+C >> copy `r`nAlt+V >> paste `r`nAlt+Left Arrow >> cycle back `r`nAlt+Right Arrow >> cycle forward`r`nAlt+H >> display this message

DISCLAIMER: I didn't write this code myself. I just modified it. The original script can be found here.


Solution

  • This is how I solved it. I even store the values in a file, so they stay in "memory" after a reboot....

    +#F1:: ; Shift Windows F1
    M1=
    Sleep, 50
    Send, ^c
    Clipwait
    Sleep, 100
    M1 = %clipboard%
    IniWrite, %M1%, C:\Tmp\Robert.ini, Memory, M1
    TrayTip, Copy,Data stored in M1,1,1
    return
     #F1:: ; Windows + F1
    If M1 =
    {
      IniRead, M1, C:\Tmp\Robert.ini, Memory, M1
    }
    ClipBoard = %M1%
    Send, ^v
    TrayTip, Paste,Data pasted from M1,1,1
    Return
    

    Then did the same for Windows + F2 ..... Windows + F4

    Hope this helps

    Oh, b.t.w. this strips all formatting from your data....