Jump to content
Macro Express Forums

Old chestnut - unreliable clipboard copying


terrypin
 Share

Recommended Posts

Of all the problems I have, getting stuff copied reliably to the clipboard is by far the most frequent. This morning I've already spent an hour on what should be a pretty trivial macro. Whatever delays I introduce, whatever keystroke speeds I use (10ms, 20ms, 50ms), I still can't seem to get the selected text into the clipboard. Instead it usually seems to hold the previous (or even older) copy.

 

Does this ring a bell with anyone please? Are there any other things I can try?

 

Here's the current example. I left-click an entry to make it editable, copy that (automatically selected) string to the clipboard, remove the highlighting (probably a redundant step), and store the clipboard contents in a variable. But if I paste the clipboard to a text editor directly after running this, I can see it's usually not copied correctly what was selected.

 

// Copy Name to T1, from already open Properties (at preset size & position)
// Assumes entry selected and mouse hovered
// L click entry to make it editable
Keystroke Speed: 20 Milliseconds
Mouse Speed: 1 Milliseconds
Mouse Left Button Click
Delay 600 Milliseconds
Text Type: <CONTROL>c
Delay 100 Milliseconds
Text Type: <ESC>
// Put name in string variable T1
Variable Set String %T1% from Clipboard
Variable Save Text Variables
Macro Return

 

Any advice would be appreciated please.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Instead of

Text Type: <CONTROL>c

try using

Text Type: <ControlDown>c<ControlUp>

 

Instead of

Delay 100 Milliseconds

after the copy-to-clipboard, use Options | Preferences | Delays | Delay after clipboard -- I believe the default is 250 milliseconds, which seems to work pretty well, if not bump it up to 500 milliseconds and try that. Using the Preference just saves you having to code the delay after each copy-to-clipboard.

 

No guarantees, but maybe these methods will help.

Link to comment
Share on other sites

Instead of

Text Type: <CONTROL>c

try using

Text Type: <ControlDown>c<ControlUp>

 

Instead of

Delay 100 Milliseconds

after the copy-to-clipboard, use Options | Preferences | Delays | Delay after clipboard -- I believe the default is 250 milliseconds, which seems to work pretty well, if not bump it up to 500 milliseconds and try that. Using the Preference just saves you having to code the delay after each copy-to-clipboard.

 

No guarantees, but maybe these methods will help.

 

Thanks, appreciate the fast reply. But after another hour or so of further head scratching I've found the cause ;) Turns out to be the same issue that keeps catching me out: shortkey settings. In the past I've had frustrating cases in which a simple macro didn't work, and I eventually solved them after a suggestion from Joe Weinpert last November. I changed the setting to Do Not Remove Keystrokes Typed on those occasions and the macros ran fine. But I've therefore slipped into the habit of setting that for all my macros! This latest one just needs the default Global setting. With that restored, the clipboard is working again, with lots of tolerance on timings.

:rolleyes:

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Instead of

Text Type: <CONTROL>c

try using

Text Type: <ControlDown>c<ControlUp>

 

Instead of

Delay 100 Milliseconds

after the copy-to-clipboard, use Options | Preferences | Delays | Delay after clipboard -- I believe the default is 250 milliseconds, which seems to work pretty well, if not bump it up to 500 milliseconds and try that. Using the Preference just saves you having to code the delay after each copy-to-clipboard.

 

No guarantees, but maybe these methods will help.

 

I'm glad the issue was something else and is now resolved.

 

However, in addition to the solutions above which work for me too, I also use the "Wait Text Playback" command immediately after a Text Type command. The wait text playback also helps when nothing else seems to work, especially with copying and pasting text from the clipboard. Perhaps our macros sometimes run faster than the computer can keep up!?

Link to comment
Share on other sites

I'm glad the issue was something else and is now resolved.

 

However, in addition to the solutions above which work for me too, I also use the "Wait Text Playback" command immediately after a Text Type command. The wait text playback also helps when nothing else seems to work, especially with copying and pasting text from the clipboard. Perhaps our macros sometimes run faster than the computer can keep up!?

 

Thanks for that tip, which I'll try when my next macro refuses to work!

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Of all the problems I have, getting stuff copied reliably to the clipboard is by far the most frequent. This morning I've already spent an hour on what should be a pretty trivial macro. Whatever delays I introduce, whatever keystroke speeds I use (10ms, 20ms, 50ms), I still can't seem to get the selected text into the clipboard. Instead it usually seems to hold the previous (or even older) copy.

 

Does this ring a bell with anyone please? Are there any other things I can try?

I always clear the clipboard first before copying to it, so that when I paste back I can check for zero-length strings. If you do this, don't use the Clipboard Empty command - it's very slow. Instead, set a string variable to "" and copy that to the clipboard.

 

For important clipboard stuff I have written 2 macros, one for copying and one for pasting. Both contain Repeat loops; the copy macro repeats (once every 100 milliseconds for a maximimum of 1 second) until there's a non-zero length string in the clipboard, while the paste macro repeats (with the same time constraints) until something has been retrieved from the clipboard.

Link to comment
Share on other sites

Paul, thanks for the clever tip on copying a null string to the clipboard. The Clipboard Empty command has never worked for me at all. And I like your loop technique better than using the ME delay-after-clipboard parameter, with its uncertain reliability.

 

A question, though -- would it speed things up to do the loop perhaps every 10 milliseconds rather than every 100? I have an interactive application where the user is waiting impatiently while a macro copies data off a screen. 100 milliseconds doesn't seem like much, but when it is repeated 20 or 30 times for a screen it is definitely noticeable.

 

For what it's worth, I have also found that it is much faster if you can capture controls, then "get control text" directly to a variable rather than via clipboard copy. That has the additional advantage of leaving the cursor wherever the user put it, not moving it all over the screen to accommodate the clipboard copy.

Link to comment
Share on other sites

I suppose you could try 10; the thing is you don't want your macro to be hogging all the resources, otherwise the clipboard will never work because the machine is too busy checking on the clipboard! But I daresay 10 is OK. Of course, in a perfect world you'd only have to wait, at most, one loop time increment.

 

I've never had much joy with controls. I'm for ever finding that some value captured as part of a control's identity can change from one run to the next, which renders the concept fairly useless! But thanks for the info.

Link to comment
Share on other sites

  • 1 month later...

No problem.

 

There are 2 macros, one to copy to the clipboard, and one to paste from the clipboard. The first one also pastes from the clipboard (otherwise it can't determine the success of the copy operation).

 

1) Clipboard Copy

This macro copies the contents of T99 to the clipboard if T99 is not blank; otherwise it copies selected text (text already selected in the active window). T98 will hold the pasted contents (so there's really no need to run the clipboard copy routine), and N99 is used for the counter.

<REM2:[ Sub - Clipboard Copy ]><REM2:If T99 is not blank, copies its contents to the clipboard, otherwise copies selected text><REM2:Overwrites T98 and N99><REM2:><REM2:Clear clipboard - this technique is much faster than using Clipboard Empty><TVAR2:98:01:><TMVAR2:16:98:00:000:000:><REM2:><REM2:Loop through for up to 1000 milliseconds until we have a value><IVAR2:99:01:100><REP3:01:000001:000001:00010:0:01:><IFVAR2:1:99:2:><TMVAR2:16:99:00:000:000:><ELSE><CLIPC><ENDIF><TVAR2:98:03:><IFVAR2:1:98:2:><EXITREP><ENDIF><MSD:%N99%><ENDREP>

 

2) Clipboard paste

T99 will hold the pasted contents, and N99 is used for the counter.

<REM2:[ Sub - Clipboard Paste ]><REM2:Overwrites T99 and N99><REM2:><REM2:Loop through for up to 1000 milliseconds until we have a value><IVAR2:99:01:100><TVAR2:99:01:><REP3:01:000001:000001:00010:0:01:><REM2:Retrieve clipboard into T99 and make sure it's not blank><TVAR2:99:03:><IFVAR2:1:99:2:><EXITREP><ENDIF><MSD:%N99%><ENDREP>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...