AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Preserving old clipboard between cut and paste operation

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
caveatrob



Joined: 28 Oct 2006
Posts: 114

PostPosted: Sun May 18, 2008 10:46 pm    Post subject: Preserving old clipboard between cut and paste operation Reply with quote

Hi all,

I'd like to preserve the clipboard before a script runs that uses the clipboard, so that when the script finishes the old clipboard is available.

I have the following code:

Uses the clipboard for a shortcut key:
Code:


cutActiveLine()
   var:=clipboard
   StringLower,var,var,T
   var=%var%
   clipboard =Hi %var%,`r`n`r`n
   send,^v

;{Home}Hi {end}{backspace},`r`n

return


Cuts the active line (this might need some modification)
Code:

cutActiveLine()
{
   
 ClipBoard=
   Send,{Home}+{End}       ;Select line
   Send,^x                 ;copy selected text to clipboard
   ClipWait,2
   If ErrorLevel
      MsgBox, The attempt to copy text onto the clipboard failed.
   Return
   
}


I've tried using the oldClipboard=clipboardAll as the first line of the CutActiveLine and removing the clipboard=. statement, but the script doesn't work when I make these changes.
Back to top
View user's profile Send private message
TheIrishThug



Joined: 19 Mar 2006
Posts: 370

PostPosted: Sun May 18, 2008 11:10 pm    Post subject: Reply with quote

From the Clipboard page of the help:
Code:
ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.
; ... here make temporary use of the clipboard, such as for pasting Unicode text via Transform Unicode ...
Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
Back to top
View user's profile Send private message Visit poster's website AIM Address
caveatrob



Joined: 28 Oct 2006
Posts: 114

PostPosted: Mon May 19, 2008 9:34 pm    Post subject: Clipboard sometimes pastes old clipboard Reply with quote

Sometimes when I run this script I get the old clipboard value as a result. Is there a timing problem in the script? How might I change this script to be more reliable?
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 497

PostPosted: Mon May 19, 2008 10:24 pm    Post subject: Reply with quote

Look into Clipwait
http://www.autohotkey.com/docs/commands/ClipWait.htm
Back to top
View user's profile Send private message
caveatrob



Joined: 28 Oct 2006
Posts: 114

PostPosted: Mon May 19, 2008 10:32 pm    Post subject: Clipwait Reply with quote

Already doing so with a ClipWait,2. Should I set the value higher?
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 497

PostPosted: Mon May 19, 2008 10:44 pm    Post subject: Reply with quote

Try something like this, untested:
Code:
cutActiveLine()
var:=Clipboard
StringLower,var,var,T
clipboard=Hi %var%,`r`n`r`n
send,^v
Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
return

cutActiveLine()
{
ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.
ClipBoard= ; to make clipwait work, see documentation
Send,{Home}+{End}       ;Select line
Send,^x                 ;cut selected text to clipboard
ClipWait,2
If ErrorLevel
    MsgBox, The attempt to copy text onto the clipboard failed.
}
Back to top
View user's profile Send private message
[VxE]



Joined: 07 Oct 2006
Posts: 1125

PostPosted: Tue May 20, 2008 12:11 am    Post subject: Reply with quote

Code:
ClipSaved := ClipboardAll   ; Save the entire clipboard to a variable of your choice.
Clipboard := "" ; clear the clipboard so that clipwait works properly
; ... code during which something should be moved into the clipboard
Clipwait, 2 ; , 1 ; uncomment the ", 1" to wait for any kind of data to go in the clipboard.
; ... code to handle the new data in the clipboard
Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).


maybe this will help. It's the same kind of thing in HugoV's reply, but not buried under a function. Razz
_________________
My Home Thread
More Common Answers: 1. It's in the FAQ 2. Ternary ( ? : ) guide 3. Post code with [code][/code] tags
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group