Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Clipboard History


  • Please log in to reply
3 replies to this topic
ManaUser
  • Members
  • 1121 posts
  • Last active: Dec 07 2016 04:24 PM
  • Joined: 24 May 2007
There are several good scripts that implement multiply clipboards one way or another, but I wanted something a little more "set and forget". Basically this is like the command history in DOS or many other text consoles. It records the last 10 (adjustable) bits of text you copied. Then you can flip back through them back through them by pressing Win+Up. The active item (or beginning and end, if it's long) is displayed in a tooltip. Once you select the one you want you can paste it as normal. You can also easily clear all or part of the history in case you've copied something sensitive like a password.

;Clipboard History, By ManaUser

;Command          Key                   Alternate (commented out)
;Older            Win + Up              Win + A
;Newer            Win + Down            Win + Z
;Delete Current   Win + Delete          Win + X
;Clear History    Win + Shift + Delete  Win + Shift + X
;Empty Clipboard  Win + Ctrl  + Delete  Win + Ctrl  + X

MAX_CLIPS = 10
TIP_DELAY = 2

#SingleInstance Force
#NoEnv

LastClip = 0
Menu TRAY, Icon, Shell32.dll, 22, 1
SetTimer WatchWait, -1000
Return

;#a::
#Up::
   If (LastClip = 0)
      Return
   CurClip--
   If (CurClip < 1)
      CurClip := LastClip
   Temp := SavedShortClip%CurClip%
   ToolTip %Temp%
   SetTimer KillToolTip, % TIP_DELAY * -1000
   Watch := 0
   Clipboard := SavedClip%CurClip%
   SetTimer WatchWait, -1000
Return

;#z::
#Down::
   If (LastClip = 0)
      Return
   CurClip++
   If (CurClip > LastClip)
      CurClip := 1
   Temp := SavedShortClip%CurClip%
   ToolTip %Temp%
   SetTimer KillToolTip, % TIP_DELAY * -1000
   Watch := 0
   Clipboard := SavedClip%CurClip%
   SetTimer WatchWait, -1000
Return

;#x::
#Delete::
   If (LastClip = 0)
      Return
   SavedClip%CurClip% =
   SavedShortClip%CurClip% =
   Temp =
   Collapse(CurClip)
   ToolTip History Item Deleted.
   SetTimer KillToolTip, % TIP_DELAY * -1000
Return

;#+x::
#+Delete::
Loop %MAX_CLIPS%
{
   SavedClip%A_Index% =
   SavedShortClip%A_Index% =
}
LastClip := 0
NewClip := 0
CurClip := 0
ToolTip Clipboard History Cleared.
SetTimer KillToolTip, % TIP_DELAY * -1000
Return

OnClipboardChange:
If (Watch = 0 OR A_EventInfo = 0 )
{
   Watch := 0                 ; For improved compatibility with
   SetTimer WatchWait, -1000  ; other AutoHotkey scripts that
   Return                     ; access the clipboard.
}
If (A_EventInfo = 1) ;Text
{
   NewClip++
   If ( NewClip > MAX_CLIPS)
      NewClip := 1
   If ( NewClip > LastClip)
      LastClip := NewClip
   CurClip := NewClip
   SavedClip%NewClip% := ClipboardAll
   Temp := Clipboard
   Temp := RegExReplace(Temp, "^\s*|\s*$", "")
   If (StrLen(Temp) > 100 OR InStr(Temp, "`n") )
      Temp := RegExReplace(Temp, "`as)^([^`r`n]{1,50}).*?([^`r`n]{1,50})$", "$1...`n...$2")
   SavedShortClip%NewClip% := Temp
   Loop %LastClip%
   Temp =
}
Return

;#^x::
#^Delete::
Clipboard =
ToolTip Clipboard Cleared.
SetTimer KillToolTip, % TIP_DELAY * -1000
Return


Collapse(Position)
{
   Global
   If (CurClip > Position)
      CurClip--
   Loop ;While Position < LastClip
   {
      Temp := Position + 1
      SavedClip%Position% :=SavedClip%Temp%
      SavedShortClip%Position% :=SavedShortClip%Temp%
      Position++
      If (Position >= LastClip)
         Break
   }   
   SavedClip%LastClip% =
   SavedShortClip%LastClip% =
   LastClip--
   If (NewClip > LastClip)
      NewClip := LastClip
}

KillToolTip:
Tooltip
Return

WatchWait:
Watch := 1
Return
Note, if the clipboard becomes empty, this script will stop "watching" for one second. This minimizes interference from other AutoHotkey scripts that use the clipboard to retrieve text, since they normally first empty the clipboard in preparation for using ClipWait.

ddungaro
  • Guests
  • Last active:
  • Joined: --
Thanks for the great script, it went straight to my startup list.

I've added the code below. It will show a menu with all the saved clipboards, so it's easier to visualise and choose when you have many of them.


#Space::
Menu, ClipbrdHist, Add
Menu, ClipbrdHist, DeleteAll
Loop %LastClip%
{
  Menu, ClipbrdHist, Add, % ((A_Index = CurClip) ? "*" : "") A_Index . ": " . SavedShortClip%A_Index%, ChangeClip
}
Menu, ClipbrdHist, show
return

ChangeClip:
CurClip := A_ThisMenuItemPos
Watch := 0
Clipboard := SavedClip%CurClip%
SetTimer WatchWait, -1000
return


Leochaton
  • Members
  • 1 posts
  • Last active: Dec 17 2008 04:45 PM
  • Joined: 17 Dec 2008
Hi,

I really like this clipboard, thanks ManaUser!

I have a weird problem with excel, when I copy a cell (text or numbers) it does not get registered in the clipboard history.

I did a Control+Windows+C hotkey to handle this assuming that it was a excel formatting issue, while it worked, it put 3 times the same text, I didn't understand why, so I started commenting lines; this is the script at the end, it only sends Control+C and it works, but I don't know why, any ideas?

^#c::	
;Watch := 0
Send, ^c
;ClipWait
;TEMPclipboard := clipboard
;StringReplace, TEMPclipboard, TEMPclipboard, `r`n, , All
;Watch := 1
;Clipboard := TEMPclipboard
return

BTW ddungaro, your addition just makes this clipboard perfect, thanks!
Gustavo

joemoeschmoe
  • Members
  • 25 posts
  • Last active: Aug 11 2009 10:15 PM
  • Joined: 25 Jun 2008
I agree with the above. The together, this is very useful. There's much less to learn than with other Clipboard enhancers.

Very nice and convenient for someone like me who doesn't need to use the history very often, so I don't want to learn a whole new setup.