Jump to content

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

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


  • Please log in to reply
40 replies to this topic
skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
ClipStep - Control multiple clipboards using only the keyboard's Ctrl-X-C-V

Select some text, press Ctrl-C to copy it to multiple new clipboards.
Now hold down Ctrl and press V repeatedly to step through the clipboards. C steps backwards.
When you've got the clipboard you want, release Ctrl to paste.
To delete a clipboard, hold down Ctrl, press V followed by X twice to delete, three times to delete all, or once to cancel. Release Ctrl to accept.

The clipboards are saved to separate files, so place the script in it's own folder.

Thank's to skywalka who posted this idea in another forum.

:!: Updated to v1.2: Removed a few bugs, tweaked some functions.


Skrommel


;ClipStep.ahk v1.2
;
;Control multiple clipboards using only the keyboard's Ctrl-X-C-V
;
;Select some text, press Ctrl-C a couple of times to copy it to multiple new clipboards. 
; Now hold down Ctrl and press V repeatedly to step through the clipboards. C steps backwards. 
; When you've got the clipboard you want, release Ctrl to paste. 
; To delete a clipboard, hold down Ctrl, press V followed by X twice to delete, three times to 
; delete all, or once to cancel. Release Ctrl to accept. 
;
; The clipboards are saved to separate files, so place the sctipt in it's own folder. 
;
;Skrommel @2005

SetBatchLines,-1

numofclips=0
activeclip=1
paste=no
delete=no

Gosub,INDEX

LOOP:
Sleep,100
GetKeyState,state,CTRL
If state=u
{
  If delete=delete
  { 
    readclip=filearray%activeclip%
    readclip:=%readclip%
    Filedelete,%readclip%.clip
    tooltip=Deleting Clip %activeclip% of %numofclips%
    Gosub,TOOLTIP
    Gosub,INDEX
    Gosub,FINDPREV
  }
  Else
  If delete=all
  {
    tooltip=Deleting all clips
    Gosub,TOOLTIP
    Filedelete,*.clip
    numofclips=0
    activeclip=0
    filearray1=0
    Gosub,INDEX
    activeclip=%numofclips%
  }
  Else    
  If paste=paste
  {
    readclip=filearray%activeclip%
    readclip:=%readclip%
    tooltip=Pasting clip %activeclip%
    Gosub,TOOLTIP
    Gosub,PASTECLIP
  }
  delete=no
  paste=no
}
Goto,LOOP


$^x::
If paste<>no
{
  If delete=delete
  {
    ToolTip,Delete all clips
    SetTimer,TOOLTIPOFF,Off
    delete=all
    paste=yes
    Return
  }
  Else
  If delete=cancel
  {
    If numofclips<1
    {
      tooltip=No clip exists
      Gosub,TOOLTIP
      Return
    }
    readclip=filearray%activeclip%
    readclip:=%readclip%
    FileRead,Clipboard,*c %readclip%.clip
    StringLeft,clip,Clipboard,100
    ToolTip,Delete Clip %activeclip% of %numofclips%`n%clip% 
    SetTimer,TOOLTIPOFF,Off
    delete=delete
    paste=yes
    Return
  }
  Else
  {
    tooltip=Cancel
    Gosub,TOOLTIP
    delete=cancel
    paste=yes
    Return
  }
}
clip1:=ClipboardAll
Clipboard=
Send,^x
ClipWait,1
clip2:=ClipboardAll
If clip2=
{
  tooltip=Empty selection
  Gosub,TOOLTIP
}
Else
If clip1<>%clip2%
{
  tooltip=Copying to clip 1
  Gosub,TOOLTIP
  Gosub,ADDCLIP
  Gosub,INDEX
}
Else
{
  tooltip=Same selection
  Gosub,TOOLTIP
}
clip1=
clip2=
Return

 
$^c::
If paste<>no
{
  If numofclips<1
  {
    tooltip=No clip exists
    Gosub,TOOLTIP
    delete=no
    paste=yes
    Return
  }
  Gosub,FINDPREV
  Gosub,SHOWCLIP
  delete=no
  paste=paste
  Return
}
clip1:=ClipboardAll
Clipboard=
Send,^c
clip2:=ClipboardAll
If clip2=
{
  tooltip=Empty selection
  Gosub,TOOLTIP
}
Else
If clip1<>%clip2%
{
  tooltip=Copying to clip 1
  Gosub,TOOLTIP
  Gosub,ADDCLIP
  Gosub,INDEX
}
Else
{
  tooltip=Same selection
  Gosub,TOOLTIP
}
clip1=
clip2=
Return

 
$^v::
If numofclips<1
{
  tooltip=No clip exists
  Gosub,TOOLTIP
  delete=no
  paste=yes
  Return
}
If paste<>no
  Gosub,FINDNEXT
Gosub,SHOWCLIP
delete=no
paste=paste
Return


ADDCLIP:
readclip=filearray1
readclip:=%readclip%
lastclip=%readclip%
lastclip+=1
numofclips+=1
activeclip=1
IfExist,%lastclip%.clip
  FileDelete,%lastclip%.clip
FileAppend,%ClipboardAll%,%lastclip%.clip
Return


SHOWCLIP:
readclip=filearray%activeclip%
readclip:=%readclip%
clip1:=ClipboardAll
IfExist,%readclip%.clip
  FileRead,Clipboard,*c %readclip%.clip
StringLeft,clip2,Clipboard,100
If clip2=
  clip2=... Image
ToolTip,Clip %activeclip% of %numofclips%`n%clip2% ... 
SetTimer,TOOLTIPOFF,Off
Clipboard:=clip1
clip1=
clip2=
Return
 

PASTECLIP:
readclip=filearray%activeclip%
readclip:=%readclip%
IfExist,%readclip%.clip
  FileRead,Clipboard,*c %readclip%.clip
Send,^v
delete=no
paste=no
Return


DELETECLIP:
delete=no
paste=no
Return


TOOLTIP:
ToolTip,%tooltip%
SetTimer,TOOLTIPOFF,900
Return


TOOLTIPOFF:
ToolTip,
SetTimer,TOOLTIP,Off
Return


INDEX:
filelist=
Loop,*.clip
{
  StringTrimRight,filename,A_LoopFileName,5
  filelist=%filelist%%filename%`n
}
StringTrimRight,filelist,filelist,1
Sort,filelist,N R
StringSplit,filearray,filelist,`n
numofclips=%filearray0%
Return


FINDNEXT:
  If numofclips<1
  {
    tooltip=No clip exists
    Gosub,TOOLTIP
    delete=no
    paste=yes
    Return
  }
activeclip+=1
If activeclip>%numofclips%
  activeclip=1
Return


FINDPREV:
  If numofclips<1
  {
    tooltip=No clip exists
    Gosub,TOOLTIP
    delete=no
    paste=yes
    Return
  }
activeclip-=1
If activeclip<1
  activeclip=%numofclips%
Return


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Cool! For unformatted text and few clipboards this script is faster to use and more convenient than the other clipboard scripts posted here. Thanks for sharing it!

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:D It works with all kinds of formats, the problem is displaying them when stepping through them.

:idea: What we need is a ClipToImage function, or for Gui,Add,Image to read the clip-format.

Skrommel

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Wonderful! It really works with images and formatted text, too. Unfortunately, I see the bookmark and picture problem in MS Word still pops up its ugly head. We just have to wait until MS or Chris finds a way around.

One feature worth mentioning in the description: if a selection is copied to the clipboard through the Windows context menu (right-click/copy), it still can be pasted the original way (independent to clip-step) through the context menu (right-click/paste). It sometimes helps to let MS Word show pasted pictures, instead of just the placeholders.

skrommel
  • Members
  • 193 posts
  • Last active: Jun 07 2010 08:30 AM
  • Joined: 30 Jul 2004
:!: I originally wanted to add PrintScreen and other clips to the chain, but there seems to be all kinds of things going on with the clipboard.

Even running the script from the help file

#Persistent
return

OnClipboardChange:
ToolTip Type: %A_EventInfo%
Sleep 1000
ToolTip  ; Turn off the tip.
return

alters the clipboard and shows a message. Is it just my computer, or is there a bug here somewhere?

Skrommel

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
At least this problem I don't seem to have (XP SP2, Dell Inspiron 9300 laptop). I don't get the tooltip popping up. What is in your system?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
While reading another topic, I'd forgotten about the script above so wrote the below. Here it is in case it's of use to anyone or if there's anything of merit that can be combined with the one above:
; This script keeps a record of the clipboard contents so that in effect, you have
; more than one clipboard.  To restore the old clipboards (one by one), press the
; Win+Space or Shift+Win+Space hotkeys (or other hotkeys as configured below).
; The script give you feedback about what's on the clipboard via Tooltips.

; CONFIGURATION SECTION. SET YOUR PREFERENCES HERE:
MaxClipboards = 5  ; How many clipboards to maintain in the list.
HotkeyBack = #space  ; Hotkey to move backward through the list of clipboards.
HotkeyFwd = #+space  ; Hotkey to move forward through the list of clipboards.

; END OF CONFIGURATION SECTION

Hotkey, %HotkeyBack%, HotkeyBack
Hotkey, %HotkeyFwd%, HotkeyFwd

#Persistent
ClipIndex = 0
ClipIndexToRestore = 0

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
}
ClipIndex += 1  ; Move to the next slot.
if (ClipIndex > MaxClipboards)  ; Wrap back around to the beginning.
	ClipIndex = 1
ClipIndexToRestore := ClipIndex  ; Reset the hotkey's bookmark each time a save occurs.
ClipSaved%ClipIndex% := ClipboardAll  ; Save the current contents of the clipboard.
ToolTip, %ClipIndex%, A_CaretX, A_CaretY  ; Briefly notify the user of the item number.
SetTimer, ToolTipOff, 1000
return

HotkeyBack:
HotkeyFwd:
if ClipIndexToRestore = 0  ; No saved clipboards yet.
	return
if (A_ThisHotkey = HotkeyBack)
{
	ClipIndexToRestore -= 1  ; Move backward through the list.
	if ClipIndexToRestore <= 0  ; Wrap around to the tail end of list.
		ClipIndexToRestore := MaxClipboards
}
else  ; (A_ThisHotkey = HotkeyFwd)
{
	ClipIndexToRestore += 1  ; Move forward through the list.
	if ClipIndexToRestore > %MaxClipboards%  ; Wrap around to beginning or list.
		ClipIndexToRestore := 1
}
if StrLen(ClipSaved%ClipIndexToRestore%) = 0  ; Nothing saved, so don't do it.
{
	ToolTip Restored Clipboard #%ClipIndexToRestore% is empty., A_CaretX, A_CaretY
	SetTimer, ToolTipOff, 2000
	return
}
NoSaveClipboard := true  ; Tell OnClipboardChange not to save our clipboard change.
Clipboard := ClipSaved%ClipIndexToRestore%
ToolTip Restored Clipboard #%ClipIndexToRestore%:`n%Clipboard%, A_CaretX, A_CaretY
SetTimer, ToolTipOff, 2000
Sleep 30  ; This gives the OnClipboardChange subroutine an opportunity to run.
NoSaveClipboard := false
return

ToolTipOff:
ToolTip
SetTimer, ToolTipOff, Off
return


EXtes
  • Guests
  • Last active:
  • Joined: --
Hi skrommel

Nice work, Thanks.
I would suggest:
tooltip:="Copying to clip " . numofclips + 1
EXtes

EXtes
  • Members
  • 7 posts
  • Last active: Apr 07 2012 11:31 AM
  • Joined: 01 Oct 2005
Argh :-)
Clipboard is copied to clip 1 always, so forget about my reply

Peepsalot
  • Members
  • 24 posts
  • Last active: Dec 16 2005 04:53 PM
  • Joined: 06 Oct 2005
Awesome script. It would be cool to have it also support Shift-Delete(Cut), Ctrl-Insert(Copy), and Shift-Insert(Paste).
Apparently I'm one of the very few people that regularly uses these shortcuts. I guess I'm weird.

I'm very new to AUtohotkey, and I'm impressed with everything it is capable of. Maybe I will tinker with the script a bit tonight.

lowbatteries
  • Guests
  • Last active:
  • Joined: --
If I hit ctrl+c on a file, I get the tooltip "empty selection", where as if I use ctrl+x, it saves it as a clip and I can then paste it (works as it does in windows).

Currently, copying files with ctrl+c is effectively broken while running the script, but I can use the ctrl+insert and shift+insert mentioned by peepsalot. I had no clue those shortcuts existed.

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
lowbatteries posted in a new topic:

permanent clipboards ...
I discovered that you can create permanent clipboards by renaming the clip files from 1.clip to x.clip, or some other non-numeric name, and setting the permissions to read-only.


I guess it belongs here.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Tomas
  • Guests
  • Last active:
  • Joined: --
I wish there was a way to always only have 2 clipboards to switch between. Personally in 99% of the time I would only need 2 clipboards. Perhaps there is an easy fix to implement this.

Thanks for a great little utility!

Tomas

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007

While reading another topic, I'd forgotten about the script above so wrote the below. Here it is in case it's of use to anyone or if there's anything of merit that can be combined with the one above:


This is the very clipboard script I want. Thx Chris.But I have a problem.
I want to integrate several script into one. So I change a little your script as follow:
#Space::
#!Space::
if ClipIndexToRestore = 0  ; No saved clipboards yet.
   return
if (A_ThisHotkey = #Space)
{
   ClipIndexToRestore -= 1  ; Move backward through the list.
   if ClipIndexToRestore <= 0  ; Wrap around to the tail end of list.
      ClipIndexToRestore := MaxClipboards
}
;If (A_ThisHotkey = #!Space)
else  ; (A_ThisHotkey = HotkeyFwd)
{
   ClipIndexToRestore += 1  ; Move forward through the list.
   if ClipIndexToRestore > %MaxClipboards%  ; Wrap around to beginning or list.
      ClipIndexToRestore := 1
}
if StrLen(ClipSaved%ClipIndexToRestore%) = 0  ; Nothing saved, so don't do it.
{
   ToolTip Restored Clipboard #%ClipIndexToRestore% is empty., A_CaretX, A_CaretY
   SetTimer, ToolTipOff, 2000
   return
}
NoSaveClipboard := true  ; Tell OnClipboardChange not to save our clipboard change.
Clipboard := ClipSaved%ClipIndexToRestore%
ToolTip Restored Clipboard #%ClipIndexToRestore%:`n%Clipboard%, A_CaretX, A_CaretY
SetTimer, ToolTipOff, 2000
Sleep 30  ; This gives the OnClipboardChange subroutine an opportunity to run.
NoSaveClipboard := false
return
I have just used the hotkey #space and #+space directly in place of the "hotkey" command.
As a result ,when I press #!space, the list move backward too rather than forward. Why?
And why this line "MaxClipboards = 5" must be moved to precede all the other hotkey and hotstring?

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

when I press #!space, the list move backward too rather than forward. Why?

if (A_ThisHotkey = #Space)
Should Be:
if A_ThisHotkey = #Space

See the Variables/Expressions page for details.

And why this line "MaxClipboards = 5" must be moved to precede all the other hotkey and hotstring?

See the Scripts page (auto-execute section). It's also covered in the FAQ.