Restoring clipboard fails in some cases

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Restoring clipboard fails in some cases

09 Mar 2014, 13:03

Hi, I'm trying to temporarily save and restore clipboard contents using the standard example from documentation (below). Unfortunately it doesn't work in many cases.

For example, run the script below and then
- copy image from the top of this forum page by right-clicking on image and selecting "Copy Image",
- press Alt-X, note the delay because ClipWait is not successful,
- open Paint or similar and try to paste with Ctrl-V. Nothing happens, clipboard is lost.

Is this a known issue, a bug or I miss something? Is there a way to do this for any clipboard content?

Code: Select all

!x::
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 =
Clipboard := ClipSaved   ; Restore the original clipboard. Note the use of Clipboard (not ClipboardAll).
ClipWait, 2, 1
ClipSaved =   ; Free the memory in case the clipboard was very large.
msgbox done...
return

esc::exitapp
Last edited by m3user on 10 Mar 2014, 07:27, edited 1 time in total.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Restoring clipboard fails in some cases

10 Mar 2014, 03:09

When I tried it, there was no delay and the image pasted into Paint just fine.

Tested with:
AutoHotkey v1.1.14.03 (ANSI, Unicode 32-bit, Unicode 64-bit)
Chrome 33, Internet Explorer 11
Windows 7 SP1 x64
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: Restoring clipboard fails in some cases

10 Mar 2014, 06:14

lexikos wrote:When I tried it, there was no delay and the image pasted into Paint just fine.
Thank you very much Lexikos! I tried it on the other computer - Win7 x86 Chrome - and it worked.
I tested it further and found out that it fails on my computer when using Firefox - clipboard is not copied/restored. It works well with Chrome and IE. Native Paste works in all the cases so I wonder what is the issue.

Another fail example: if I copy a file in Windows Explorer, press Alt-X and then press Ctrl-V - the file does not paste and clipboard is lost.

Any ideas? Could anyone try to reproduce an issue?
Is there any method to detect the problem before deleting clipboard?
Thanks.
m3user
Posts: 235
Joined: 17 Jan 2014, 18:11

Re: Restoring clipboard fails in some cases

11 Mar 2014, 18:09

Found another case - the above script fails when copying the mail item from the main list in Outlook.

Could anyone confirm the issue? Any workaround for the cases I mentioned (Outlook, Firefox, sometimes Windows Explorer...)? Thanks.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Restoring clipboard fails in some cases

11 Mar 2014, 21:48

m3user wrote:Another fail example: if I copy a file in Windows Explorer, press Alt-X and then press Ctrl-V - the file does not paste and clipboard is lost.
It works just fine for me - clipboard isn't lost. I'm currently on XP.
Found another case - the above script fails when copying the mail item from the main list in Outlook.
I believe Outlook doesn't store the full data on the clipboard unless you actually close Outlook (and you click "yes" to the clipboard prompt which comes up). If I do that, there is no problem.

ClipboardAll works by iterating through the available clipboard formats, storing the data of each format. Some programs use delayed rendering and possibly other tricks, so the full data being copied isn't actually in the clipboard. I'm not sure whether the methods used by AutoHotkey will trigger delayed rendering; if not, perhaps that's the problem. However, MSDN seems to imply that it should be automatic:
The system sends the clipboard owner a WM_RENDERFORMAT message when a request is received for a specific format that has not been rendered.
Guest

Re: Restoring clipboard fails in some cases

12 Mar 2014, 18:00

Thanks for your kind response. In Outlook, if I use a normal Cut/Paste (Ctrl-C, Ctrl-V) everything works as expected, even pasting to other applications. Pasting via my script doesn't work for me.

As there are obviously some specific cases/setups when the script is not working (at least for me), is there a way to catch a problem after ClipSaved:=ClipboardAll to prevent deleting a clipboard?
RHCP
Posts: 202
Joined: 30 Sep 2013, 10:59

Re: Restoring clipboard fails in some cases

12 Mar 2014, 20:50

I've noticed that a sleep is required between freeing the clipboard and using clipboardwait to increase reliability e.g.

Code: Select all

Clipboard := "" 
sleep 200 					
send ^c
ClipWait, 1, 1 
I suspect that the clipboard isn't entirely freed before clipwait starts.

Similarly if a sleep is NOT used between a paste command and restoring the previous contents of the clipboard, sometimes the contents of clipboard buffer are pasted instead.

Code: Select all

send ^v
sleep 200 				; wait for the paste to finish before the clipabord contents are swapped back
Clipboard := buffer  	; otherwise sometimes the contents of buffer will be pasted instead
I would have assumed the the lines of code underneath an clipboard assingment/manipulation would not run until the clipboards contents were fully updated, but the above sleeps definitely improve reliability, at least for me anyway. Is this normal?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa, vanove and 161 guests