ClipBoard

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
hagchr
Automation Wizard
Posts: 327
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

ClipBoard

Post by hagchr » Mon May 23, 2016 10:01 am

I recently managed to track down an issue in one of my old scripts. It was evil in the sense that the script would work just fine but every now and then give strange results. Hopefully it can be illustrative (at least for new scripters) so here is a small example to illustrate the problem.

I basically want to paste something somewhere by using CTRL+v, and to be sure the paste is complete, I place a Dummy string into the clipboard and use a loop to check and wait for the clipboard to return the Dummy string before continuing.

Code: Select all

Let>Mess=This is a message to test the clipboard.
PutClipBoard>Mess

SetFocus>Untitled - Notepad
Wait>0.1

Press>CTRL
    SendText>v
Release>CTRL

 \\Put Dummy string into clipboard
PutClipBoard>Dummy

\\Loop to check clipboard until string Dummy is returned, then continue.
If I run it using Notepad then it works fine everytime. However, with some other applications (eg Microsoft OneNote or Word) then it sometimes works and sometimes not (sometimes the proper message is pasted, sometimes the string Dummy).

The problem, is that, even though I do the CTRL+v to paste and THEN PlaceClipBoard>, PlaceClipBoard> sometimes is faster than CTRL+v resulting in the Dummy string being placed into the clipboard and used by CTRL+v.

The solution is to add a small wait, Wait>0.1 after CTRL+v to give it time to bite, then it works fine every time.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts