1
votes

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.

3
I now use ShapeShifter, a program that works way more intuitive than AutoHotkey in this specific area.Aart den Braber

3 Answers

3
votes

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....

1
votes

I made another variation, kind of starcraft style, where you assign the selected contents to a number using ctrl+number, and access those contents again using the number from the number pad. Figured I'd post it in case you feel like trying it out. For me, it feels easier to access the content I want rather than scrolling through the history. Thanks for bringing this up in a thread. I've thought about this many times and happened to come across this thread which gave me the tools I needed

#SingleInstance force

handleClip(action, num)
{
   global static ClipArray0
   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

   if (action = "save")
   {  
      ClipArray%num% := Clipboard
   }
   else if (action = "get")
   {
      Clipboard := ClipArray%num%
      Send, ^v
   }
}

;COPY
^1::
    suspend on
    Send, ^c
    suspend off
    handleClip("save", 1)
return

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

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

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

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

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

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

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

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

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

;PASTE
Numpad1::
   handleClip("get", 1)
return

Numpad2::
   handleClip("get", 2)
return

Numpad3::
   handleClip("get", 3)
return

Numpad4::
   handleClip("get", 4)
return

Numpad5::
   handleClip("get", 5)
return

Numpad6::
   handleClip("get", 6)
return

Numpad7::
   handleClip("get", 7)
return

Numpad8::
   handleClip("get", 8)
return

Numpad9::
   handleClip("get", 9)
return

Numpad0::
   handleClip("get", 0)
return
0
votes

Another simple script which does not modify your clipboard at all, but gives you the opportunity to access your last 10 (modifiable: see first line) clipboard text entries. I myself could not live without the following anymore. More than useful for programming.

Works with: sqlite. Needed: sqlite3.dll and class_SQLiteDB.ahk

http://pastebin.com/1weXi1eX