ClipStep - Step through multiple clipboards using Ctrl-X-C-V UPDATE

Post your working scripts, libraries and tools
MancioDellaVega
Posts: 44
Joined: 16 May 2020, 12:27

ClipStep - Step through multiple clipboards using Ctrl-X-C-V UPDATE

18 Jul 2020, 08:02

I found this great script by @rrhuffy in the old forum
https://autohotkey.com/board/topic/4567-clipstep-step-through-multiple-clipboards-using-ctrl-x-c-v/page-3
and i tried to update it... the idea of the script is very amazing ... i did my best but the script needs something more...

Code: Select all

#SingleInstance, force
;#Persistent
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn  ; Enable warnings to assist with detecting common errors.

MaxClipboards := 7
usedClipboards := 0
ClipIndex := 0
guiActive := 0
NoSaveClipboard := 0
clipboard =

return


$^x::
    KeyWait, x, U T0.6    ; Long press (> 0.6 sec) on x clears the clipboards Wait no more than 0.6 sec for key release (also suppress auto-repeat)
    If ErrorLevel   
    {
    /*
        ToolTip,long press
        Sleep,1000
        ToolTip
        */
        NoSaveClipboard := 1
        Loop, %usedClipboards%
        {
           ClipSaved%A_Index% = 
        }
        
        NoSaveClipboard := 0
        usedClipboards := 0
        ClipIndex := 0
        clipboard =
        
        ToolTip, Saved Clipboards Cleared
        Sleep,3000
        ToolTip
		
        ; timeout, so long press

        
    }else{
    /*
        ToolTip,Short press
        Sleep,1000
        ToolTip
	*/
         if guiActive {
         
              ; if GUI is activated then deactivate it, and send EXIT tooltip
              
                guiActive := 0
                ToolTip, Exit
                gosub, HOLD
          
         }else{ 
             ; if GUI isn't activated then just CUT
              Send, ^x
              ClipIndextoRestore := ClipIndex
         }


    }

return

/*
$^x:: ;CUT/EXIT
 
      if guiActive {
      
           ; if GUI is activated then deactivate it, and send EXIT tooltip
           
             guiActive := 0
             ToolTip, Exit
             gosub, HOLD
       
      }else{ 
          ; if GUI isn't activated then just CUT
           Send, ^x
      }
return
*/
$^c:: ;COPY/PREV
 
      if guiActive { 
               ; if GUI is activated then move to previous clipboard and show it
      
              if (ClipIndex = 0) ; No saved clipboards yet.
                 return
               
              ClipIndex:=CycleStr(ClipIndex, "r1:" usedClipboards ":1",,-1,1)
            /*   
              ClipIndex -= 1    ; move backwards through the list.
              if ClipIndex < 1 ; Wrap around to end of list.
               ClipIndex := usedClipboards
              */ 
               
              gosub, SHOWCLIPBOARD
             
      }else{ 
            ; if GUI isn't activated then just COPY
            Send, ^c
            ClipIndextoRestore := ClipIndex  
      }
       
return

$^v:: ;PASTE/NEXT
 
      if guiActive { 
               ; if GUI is activated then move to next clipboard and show it
     
                 if (ClipIndex = 0) ; No saved clipboards yet.
                    return
                  
                 
                 ClipIndex:=CycleStr(ClipIndex, "r1:" usedClipboards ":1",,1,1)
                 
                 /*
                 ClipIndex += 1 ; Move backward through the list.
                 if ClipIndex > %usedClipboards% ; Wrap around to the beginning of list.
                  ClipIndex := 1
                  */
                 gosub, SHOWCLIPBOARD
                 
      }else{ 
               ; if GUI isn't activated then activate GUI and show first element in clipboard
           
               guiActive := 1
               ClipIndextoRestore := ClipIndex ; Reset the hotkey's bookmark each time a save occurs.
               gosub, SHOWCLIPBOARD
               
      }
return

OnClipboardChange:
        if ((A_EventInfo = 0) OR NoSaveClipboard)
           return ; Empty or the hotkey told us not to save its own change to the clipboard.
                  ; Check if what's on the clipboard now exactly matches the previously saved item. If it
                  ; does, don't save it. This solves the fact that some apps save each clipboard twice.
                  
        if (ClipIndex > 0) {
              ClipSavedTemp := ClipboardAll ; ...because can't compare directly to ClipboardAll.
              if ClipSaved%ClipIndex% = %ClipSavedTemp% ; Must be old-style if-statement.
                 return
        }
        
        /*
        if (usedClipboards + 1 > MaxClipboards){
        
             usedClipboards := MaxClipboards
             
        }else{
        
             usedClipboards += 1
             
        }
        
        */
        
        if (usedClipboards < MaxClipboards) {
            usedClipboards:=CycleStr(usedClipboards, "r1:" MaxClipboards ":1",,1,1)
        }
        
        ClipIndex:=ClipIndextoRestore
        ClipIndex:=CycleStr(ClipIndex, "r1:" MaxClipboards ":1",,1,1)
        
        
        /*
        ClipIndex += 1 ; Move to the next slot.
        if (ClipIndex > MaxClipboards) ; Wrap back around to the beginning.
         ClipIndex = 1
        ClipIndex := ClipIndex ; Reset the hotkey's bookmark each time a save occurs.
        */
        
        ClipSaved%ClipIndex% := ClipboardAll ; Save the current contents of the clipboard.
        ToolTip, Added %ClipIndex%/%usedClipboards% `n%Clipboard%
        
        gosub, HOLD
return


SHOWCLIPBOARD:

     if (StrLen(ClipSaved%ClipIndex%) = 0) {
         ; Nothing saved, so don't do it.
     
         ToolTip, Restored Clipboard #%ClipIndex%/%usedClipboards% is empty.
         gosub, HOLD
         return
     }
     
     NoSaveClipboard := 1 ; Tell OnClipboardChange not to save our clipboard change.
     Clipboard := ClipSaved%ClipIndex%
     
     ToolTip, Contenuto della Clipboard #%ClipIndex%/%usedClipboards%:`n%Clipboard%
     gosub, HOLD
     Sleep 100 ; This gives the OnClipboardChange subroutine an opportunity to run.
     NoSaveClipboard := 0
 
return



HOLD:
     GetKeyState, state, CTRL
     if (state = "D") { 
           ; While holding CTRL gui won't dissapear
            SetTimer,HOLD,100
            
     }else{
      
          ToolTip
          if guiActive { 
                   ; Only way to activate GUI is put ^v, so after release CTRL we want to deactivate GUI and PASTE
                   guiActive := 0
                   Send ^v
          }
          SetTimer,HOLD,off
      
     }
return



CycleStr(S:="", Z:="", D:="|", dir:=1, cycle:=1) {
/*
CycleStr v.1.2 by Speedmaster
  function to cycles to the next or previous value in a set of values ex. "A|B|C|D"

  CycleStr(s:="", Z:="", D:="|", dir:=1, cycle:=1)
  S = a value in the set Z.
  Z = set of values, a string of delimited values. for ex. "red|green|blue"
      you can also auto build a range for numbers syntax is "R:Min:Max:PaddingZeros" for ex. "R:25:99:3"  ==> 025|026...099
  D = Delimiters can be either a single string or an array of strings. (default is "|")
  dir = 0 go to home, 1 cycle forward, -1 cycle backward, 2 go to end
  Cycle = 0/1 allow wrapping around the end.

examples:
    CycleStr("B", "A|B|C") returns "C" next value
    CycleStr("B", "A|B|C",,-1) returns "A" previous value
    CycleStr("C", "A|B|C") returns "A" (wrap around to right)
    CycleStr("A", "A|B|C",,-1) returns "C" (wrap around to left)
    CycleStr("C", "A|B|C",,1,0) returns "C" (wrapping around disabled)
    CycleStr("33", "R:55:100:3") returns "034" (build a range of values from 055 to 100)  "055|056...100"
    CycleStr("A", "A B/C",[" ", "/"]) returns "B" (mixed delimiters are supported in an array of strings)
    CycleStr("r", "abcdefghijklmnopqrstuv","") returns "s" (if there is no delimiter values are split by chars)
;---------------------------------
;script example :
item:="cherry"
right::tooltip, % item:=CycleStr(item,"Apple|Banana|Cherry|Durian|Fig",,1) ; start at "cherry" show next value and wrap around at end
left::tooltip, % item:=CycleStr(item,"Apple|Banana|Cherry|Durian|Fig",,-1,0) ; start at "cherry" show previous value and stop at first value
home::tooltip, % item:=CycleStr(item, "Apple|Banana|Cherry|Durian|Fig",,0) ; jump to home of list
end::tooltip, % item:=CycleStr(item, "Apple|Banana|Cherry|Durian|Fig",,2) ; jump to end of list

My Examples
    CycleStr(item, "r1:8:1",,1,1)
*/

  if (regexmatch(z, "i)R:? ?(-?\d+):(-?\d+):?(\d\d?)?", num)) {
    --num1
    while (num1++ < num2) {
        if (num3!="")
            numrange .= Format("{:0" num3 "}", num1) (D?D:D:="|")
       else
            numrange .= num1 (D?D:D:="|")
    }
    z:=rtrim(numrange, (D?D:D:="|"))
  }
 oz:=strsplit(z, d), ozb:=[]
 for k, v in oz
   ozb[v,1]:=oz[(K+1)<=oz.length()?(k+1):1], ozb[v,2]:=oz[(k-1)>0?(k-1):oz.length()]
 if (dir=0)
  return ozb[oz[oz.length()],1] ; start of list dir=0
 if (dir=2) 
  return ozb[oz.1,2] ; end of list dir=2
 if (!cycle && (dir>0) && (s=oz[oz.length()]))
    return s
 if (!cycle && (dir=-1) && (s=oz[1]) && oz.length()) ;&& msgbox("")  ; cycle disabled
    return s
return, ozb[ozb[s].length()?s:(oz[(dir>0)?(oz.length()):1])][(dir>0)?1:2]   
}

Return to “Scripts and Functions”

Who is online

Users browsing this forum: hasantr and 21 guests