AutoHotkey Community

It is currently May 26th, 2012, 10:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: August 6th, 2005, 10:34 pm 
Offline

Joined: July 30th, 2004, 8:50 pm
Posts: 192
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


Code:
;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


Last edited by skrommel on August 7th, 2005, 2:57 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2005, 3:00 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: RTF
PostPosted: August 7th, 2005, 10:01 am 
Offline

Joined: July 30th, 2004, 8:50 pm
Posts: 192
: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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 7th, 2005, 5:06 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Clipboard Error?
PostPosted: August 7th, 2005, 10:56 pm 
Offline

Joined: July 30th, 2004, 8:50 pm
Posts: 192
:!: 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

Code:
#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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 8th, 2005, 5:23 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 24th, 2005, 3:34 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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:
Code:
; 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 3:02 pm 
Hi skrommel

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

EXtes


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2005, 1:04 pm 
Offline

Joined: October 1st, 2005, 12:53 pm
Posts: 7
Argh :-)
Clipboard is copied to clip 1 always, so forget about my reply


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2005, 10:20 pm 
Offline

Joined: October 6th, 2005, 7:25 am
Posts: 24
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: file copying
PostPosted: February 6th, 2006, 11:59 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 7th, 2006, 9:21 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
lowbatteries posted in a new topic:
lowbatteries wrote:
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2006, 1:40 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2007, 3:39 pm 
Offline

Joined: February 11th, 2007, 4:10 pm
Posts: 185
Chris wrote:
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:
Code:
#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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 16th, 2007, 1:36 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Quote:
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.

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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Cristi®, Google Feedfetcher, Yahoo [Bot] and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group