Jump to content

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

Strange interactions of ClipBoardAll and Send ^c


  • Please log in to reply
20 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
In MS Word the following script behaves funny (I removed all other commands until only the odd couple is left):

!z::                 ; other hotkeys behave similarly
cb = %ClipBoardAll%  ; cb := ClipBoardAll is the same
Send ^c
return

Win2K Pro, MS Word 2002 SP3 (Office XP), AHK Version 1.0.29.00

I select a word and press the hotkey twice. The selected text becomes bookmarked. I select anything and press the hotkey. Move the cursor, do some text editing and press the hotkey again. The previously selected text becomes magically bookmarked. (There are gray brackets around them.)

It is not too bad, but obviously MS Word is busy doing something for a second. It slows down everything, and the ugly gray brackets are tedious to be removed.

PowerPoint, NotePad, MultiEdit does not seem to be affected.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I'm pretty sure Word does things with the clipboard in the background (periodically checking its contents, or perhaps being in the clipboard viewer chain so that it is notified whenever something new appears on the clpboard).

Even so, I tried that hotkey in Word 2002 and couldn't get that behavior. I checked the code and I don't see why using the hotkey you mentioned above would cause a problem. This is because ClipboardAll does not change anything on the clipboard, it only reads from it.

I can see why Word might react to something like the following. Perhaps your script uses this elsewhere:
Clipboard = %cb% ; Restore a previously saved clipboard.

Other than this, I'm at a loss. Has anyone else tried using ClipboardAll in MS Word?

BoBo
  • Guests
  • Last active:
  • Joined: --
Is there an option that it interferes with MS-Words --> Tools\Options\Save - "Allow background saves" and/or "Save AutoRecover info every ..." ?

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I have allowed background saves, auto recovery etc, but disabling them doesn't do any good.

There was nothing else but these 4 lines in my test.ahk script. I also suspected that assigning data to the clipboard could cause the bookmark insertion, but as I wrote, I removed / added-back all the commands one-by-one until the above smallest misbehaving script remained. It is really perplexing: just reading the clipboard before ^c causes the side effects.

Obviously MS Word does something fancy with Ctrl-c. If I press Ctrl-c wait a second and press it again, nothing unusual happens. But if I press it twice in rapid fire, the Office Clipboard opens. Maybe, the problem is that Ctrl-c in WinWord copies the selection to the Windows clipboard *and* to the topmost position of the 24 Office clipboards. This procedure is smart: if you don't change the selection, just press Ctrl-c again no new Office clipboard position will be consumed. It shows, that MS Word remembers the last selection. The Office Help says:

The Office Clipboard is related to the system Clipboard in the following ways:
• When you copy multiple items to the Office Clipboard, the last item you copy is always copied to the system Clipboard.
• When you clear the Office Clipboard, the system Clipboard is also cleared.
• When you use the Paste command, the Paste button, or the shortcut keys (CTRL+V), you paste the contents of the system Clipboard, not the Office Clipboard.

It is not the speed. If I insert "Sleep 2000" before the "Send ^c" the bookmarks still appear.

Replacing ClipBoardAll with ClipBoard stops the bookmarking. I suspected that reading the clipboard involves a query, or list of objects and descriptors system call, and this has a side effect.

If you wish, you can make the script even shorter:
!z::
cb := ClipBoardAll
return
Mark something in Word, copy it to the clipboard by Ctrl-c. Do some editing, change to another window, save your work, etc, but upon returning to the original window, running the script by Alt-z bookmarks the last selection. You see that it is pretty sophisticated: the demon behind remembers the window and the position of the last selection, not only its content.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I see what you mean now. I had bookmarks disabled, so I went into Tools > Options > View, and then checked the "bookmark" box. When I use ClipboardAll, it does indeed cause a bookmark to appear as you described.

You've probably already rejected this, but if you're not using the bookmarks feature, you could turn it off by unchecking its box in Tools > Options > View.

I did a brief search of the newgroups and MSDN and didn't find anything related to this behavior.

I tested the code some more and narrowed down the problem to GetClipboardData(), which is called once for each format on the clipboard. In the case of MS Word, there are over 16 formats on the clipboard when you copy even a single word.

A simple solution is this is to have the program ignore all formats that occur after the Text/Unicode format. Chances are, those formats are constructed on demand and thus do not need to be retrieved. And as it turns out, accessing one or more of these tail-end formats is what causes a bookmark to appear.

The problem with this is that there is apparently no way to find out for certain which MS Word data on the clipboard is real and which is derived on demand, so it would be largely guesswork.

In summary, the tentative solution is to provide a ClipboardLimited or ClipboardCore variable that is a subset of ClipboardAll, omitting suspicious formats in the name of minimizing memory consumption and avoiding side-effects.

Achim
  • Guests
  • Last active:
  • Joined: --
I am using this code snipped quite a lot with MS Word 2003 without problems. Perhaps because I switched off the MS office clipboard manager?

Try: Menu View -> Task pane, go to "clipboard" pane, bottom menu "option", switch off all switches.

BTW, I'm using CLCL clibbord manager instead, which is as powerful, but independent of office.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Thanks, Achim! It is quite counter intuitive switching off the office clipboard icon in the tray to solve the bookmark problem, and it did not solve it in Office XP. We just have to love Windows!

I tried to download the CLCL clipboard manager, but all the links I found were broken (if you know one, could you post a live URL?). Besides, the descriptions tell it was shareware, not free, and also only for text clipboards. The same functionality we can have with a one page AHK script for free, with the source code so anybody can customize it to his needs.

Nemroth
  • Members
  • 278 posts
  • Last active: Dec 31 2011 10:53 PM
  • Joined: 07 Sep 2004
Here it is : CLCL

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Thanks! For others interested: It turned out that the descriptions Google found were wrong. CLCL version 1.1.2 is free and can handle any clipboard. It keeps the specified number of clipboards you created in a queue and later you can go back and paste those in any order in any applications. For a few formats CLCL gives a preview of the cached clipboard. If text and pictures are copied to the clipboard from MS Word, looking at them in enhanced Metafile format CLCL shows them correctly.

By the way, CLCL probably uses the same mechanism to catch the clipboard as AHK. If CLCL is running Ctrl-C bookmarks the selection in MS Word, causing the same ugly gray brackets as %ClipBoardAll%. I have to disable showing bookmarks in Word (Tools/Options/Wiew, in the group Show uncheck Bookmarks), or live with the brackets. But otherwise bookmarks are useful, so I'd rather keep them shown.

Th functionality of CLCL is complementary to my Deluxe Clipboard script, where you can name you clipboards as you create, so they are automatically organized.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
To beat the dead horse a little more...
!a::
Send ^c
a = %ClipBoardAll%
return

!b::
Send ^c
b = %ClipBoardAll%
return

!c::
Clipboard = %a%
Send ^v
return
Still in MS Word. If I select a picture, hit Alt-A then Alt-C, the picture is copied to the new location. Wunderbar! Now select anything else, hit Alt-B (which should not disturb) and Alt-C again. The same picture is copied to the insertion point, but it is not visible, only a placeholder. Now go back to your picture, and select it and press Alt-A again. Don't do anything else! The placeholder jumps to live: it is a picture now (you might have to page up or down to get the screen redrawn).

It looks like Microsoft made MS Word as incompatible to Windows as possible. If you don't use the Office clipboard it inserts this ugly bookmarks, does not show pictures, etc. And it is not AHK. I can reproduce the exact same behavior with CLCL.

Does anyone know a workaround? Ask your parents, friends, relatives! These drive me crazy.

JSLover
  • Members
  • 920 posts
  • Last active: Nov 02 2012 09:54 PM
  • Joined: 20 Dec 2004

If CLCL is running Ctrl-C bookmarks the selection in MS Word, causing the same ugly gray brackets as %ClipBoardAll%.

...I don't have (a registered {$$$} version of) Office (to test with {what I have on my comp came with it & needs paid for before I can use it...I'm stuck with MS Works}), but I assume Office has its own shortcut key designed to bookmark the current selection...a) does pressing this key (whatever it is...Ctrl+B, Ctrl+Alt+B...???) create AND delete the bookmark...or only create it? B) if it only creates it, is there another key (Ctrl+Shift+B, Ctrl+Shift+Alt+B...?) to remove the currently selected bookmark? If you can delete the current bookmark (with a shortcut key or a Send/PostMessage)...

!z::                 ; other hotkeys behave similarly
cb = %ClipBoardAll%  ; cb := ClipBoardAll is the same
Send ^c^+b           ; ^+b is my guess at the "remove bookmark" shortcut key
return
...if it does it too fast in the same Send line...

!z::                 ; other hotkeys behave similarly
cb = %ClipBoardAll%  ; cb := ClipBoardAll is the same
Send ^c              ; moved ^+b to its own line, could be slow enough just by doing that, but...
;Sleep, 100          ; still not slow enough? uncomment Sleep
Send ^+b             ; ^+b is my guess at the "remove bookmark" shortcut key
return
...if you can't find a "remove (current) bookmark" shortcut key, look in the menus for an item that does it & get Winspector Spy & press that item while the spy is watching & get the command number, then send that...

!z::                                             ; other hotkeys behave similarly
cb = %ClipBoardAll%                              ; cb := ClipBoardAll is the same
Send ^c
;Sleep, 100                                      ; too Sleep or not to Sleep, that is the question
SendMessage, Msg [, wParam, lParam, Control, a]  ; Msg, wParam, lParam...from WS Spy. a=active window...may want to limit to Office???
return

Useful forum links: New content since: Last visitPast weekPast 2 weeks (links will show YOUR posts, not mine)

OMFG, the AutoHotkey forum is IP.board now (yuck!)...I may not be able to continue coming here (& I love AutoHotkey)...I liked phpBB, but not this...ugh...

Note...
I may not reply to any topics (specifically ones I was previously involved in), mostly cuz I can't find the ones I replied to, to continue helping, but also just cuz I can't stand the new forum...phpBB was soo perfect. This is 100% the opposite of "perfect".

I also semi-plan to start my own, phpBB-based AutoHotkey forum (or take over the old one, if he'll let me)
PM me if you're interested in a new phpBB-based forum (I need to know if anyone would use it)
How (or why) did they create the Neil Armstrong memorial site (neilarmstronginfo.com) BEFORE he died?

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004

I'm stuck with MS Works


Stuck with? You do realize there are countless alternatives, yes? Personally, I use OpenOffice, but that's partly to have the same one as on my *nix machine. I'm there are tons of great freeware and open source word processors for Windows.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
You can probably ditch Works, but I am really stuck with MS Word. Feel free to be sorry for me. My laptop belongs to my employer and I have to use Word for all of my documents I write for living. You can try to be smart and use something else, like Open Office and save the document in Word format, but whatever I've tried so far had some incompatibility in formatting, in the references, etc. Maybe I have to look for another job…

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Thanks JSLover! Unfortunately your suggestions don't really work for me. Please look further…

On the Insert menu, click Bookmark…It brings up a list of all the active bookmarks. However, you cannot select multiple ones, can only delete them one by one. At least the unwanted ones have the names of OLE_LINK1, OLE_LINK2… ad infinitum, so they are together when sorted by name (an option there). I add my own bookmarks informative names, and the names of cross reference items start with an underscore, so I can tell them apart. This one-by-one bookmark-deleting is what I called tedious.

The only shortcut key for handling bookmarks in Word is Ctrl-Shift-F5. It just brings up the menu item Bookmarks. I can probably write a whole page script to open up this menu, look for the text OLE_LINK and delete the corresponding bookmark. It has to detect if the current window is Word, too, otherwise do nothing. And these don't solve the hide-and-seek with the pasted pictures. The bookmark brackets are just annoying, but an invisible picture makes the document unusable. I still need a solution!

If you copy text to the Windows clipboard and save it into an AHK variable *after* a picture was copied and saved, NO Word document shows pasted pictures properly. (The clipboard is reloaded from and AHK variable and pasted by Ctrl-V). You have to make sure that the last saved clipboard was a picture. Then pasting other pictures works, too.


  • Guests
  • Last active:
  • Joined: --

Perhaps because I switched off the MS office clipboard manager?

Try: Menu View -> Task pane, go to "clipboard" pane, bottom menu "option", switch off all switches.


Achim, that clipboard manager is driving me nuts, but I have not been able to permanently disable it. How can I do that? The menu path you described above is not present in Excel 2000. I have Office 2000 and want to disable the clipboard manager everywhere. (I actually just want it do stop nagging me with a dialog when it's full and has to drop the oldest item.)

Please respond via e-mail to krilbe curly-a home dot se. I don't frequent this forum - just found your post via Google.

Many thanks,
Kjell