| View previous topic :: View next topic |
| Author |
Message |
caveatrob
Joined: 28 Oct 2006 Posts: 114
|
Posted: Sun May 18, 2008 10:46 pm Post subject: Preserving old clipboard between cut and paste operation |
|
|
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 |
|
 |
TheIrishThug
Joined: 19 Mar 2006 Posts: 370
|
Posted: Sun May 18, 2008 11:10 pm Post subject: |
|
|
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 |
|
 |
caveatrob
Joined: 28 Oct 2006 Posts: 114
|
Posted: Mon May 19, 2008 9:34 pm Post subject: Clipboard sometimes pastes old clipboard |
|
|
| 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 |
|
 |
HugoV
Joined: 27 May 2007 Posts: 497
|
|
| Back to top |
|
 |
caveatrob
Joined: 28 Oct 2006 Posts: 114
|
Posted: Mon May 19, 2008 10:32 pm Post subject: Clipwait |
|
|
| Already doing so with a ClipWait,2. Should I set the value higher? |
|
| Back to top |
|
 |
HugoV
Joined: 27 May 2007 Posts: 497
|
Posted: Mon May 19, 2008 10:44 pm Post subject: |
|
|
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 |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1125
|
Posted: Tue May 20, 2008 12:11 am Post subject: |
|
|
| 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.  _________________ 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 |
|
 |
|