Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Can't open clipboard for reading.


  • Please log in to reply
11 replies to this topic
Josh
  • Guests
  • Last active:
  • Joined: --
I keep getting an error message in the middle of my script saying "Can't open clipboard for reading."

The error message is always in the same spot and this particular portion is in the script several times.

The script I am using is designed to loop as many times as I enter in the beginning. I usually need it to run 1000 times and sometimes more.

The spot where I get the message is

Loop
{
if clipboard = %InvNum%
{
Sleep, 250
Send, ^c
Continue
}
Else
{

The if clipboard is the spot where it points the error too.

If I press OK on the message it will continue the script.

Is there a way to detect if it cannot read the clipboard and retry in about .25 seconds? I cannot have this message popping up every 20 or so loops.

  • Guests
  • Last active:
  • Joined: --

I keep getting an error message in the middle of my script saying "Can't open clipboard for reading."

The error message is always in the same spot and this particular portion is in the script several times.

The script I am using is designed to loop as many times as I enter in the beginning. I usually need it to run 1000 times and sometimes more.

The spot where I get the message is

Loop
{
if clipboard = %InvNum%
{
Sleep, 250
Send, ^c
Continue
}
Else
{

The if clipboard is the spot where it points the error too.

If I press OK on the message it will continue the script.

Is there a way to detect if it cannot read the clipboard and retry in about .25 seconds? I cannot have this message popping up every 20 or so loops.

Because you do not show the rest of the loop, I will have to guess at an answer. If the 'else' part of your code executes to fast there may be a problem doing "if clipboard" to quickly. Try something like this as a possible solution.
Loop { 
  if clipboard = %InvNum% 
  { 
    Sleep, 250 
    Send, ^c 
   Continue 
  } 
Else 
  {
    ; some other code
    sleep, 100		; slow down the calls to reading clipboard
  }
}
And please use the code tags when pasting code to the forums.

Chavez
  • Members
  • 256 posts
  • Last active: Oct 13 2009 01:27 PM
  • Joined: 20 Aug 2008

Loop 

{ ;You OPEN the loop here

if clipboard = %InvNum% 

{ ; You OPEN the 'IF' here

Sleep, 250 

Send, ^c 

Continue 

} ; You CLOSE the 'IF' here

Else 

{ ; You OPEN the 'ELSE' here



;Poof, The Loop is still opened! Error! Close the loop with '}' at the end of your code ;3


-Chavez.

Josh
  • Guests
  • Last active:
  • Joined: --
The rest of that part is

Loop
	{ If clipboard = %InvNum%
		{ Sleep, 250
		Send, ^c
		Continue
		}
	Else
		{ Break
		}
	}

The reason I didnt post it all is becuase I didnt want to go digging though 500 lines so I just copied what I saw on the error message box.

I have this same script about 8 times in mine and this portion is the only problem. The only difference is the variable on the others.

  • Guests
  • Last active:
  • Joined: --

The rest of that part is

Loop
	{ If clipboard = %InvNum%
		{ Sleep, 250
		Send, ^c
		Continue
		}
	Else
		{ Break
		}
	}

The reason I didnt post it all is becuase I didnt want to go digging though 500 lines so I just copied what I saw on the error message box.

I have this same script about 8 times in mine and this portion is the only problem. The only difference is the variable on the others.

Something looks strange here. You are looking for some particular data on the clipboard,
then you are going to paste it into another program (^c). So either another part of your
script or another program is putting sometbing on the clipboard. This action does take
some time to complete, during which you will not be able to read the clipboard.

According to info on msdn (and common sense) this error occurs because:
"Another application is using the Clipboard and will not release it to your application"

If it is your script putting data on the clipboard, I suggest you put a small sleep statement
after the 'clipboard write'. If it is another (asynchronous) program using the clipboard
the following addition to your code might solve the problem. But this is untested as
I have not been able to duplicate the problem.

Loop 
   { 
;;;;;;;;;;;;;;;;; added code start
   loop {				; if clipboard is owned wait up to 10 seconds for release
     if DLLCall("GetClipboardOwner") {
       if (A_Index > 100) {
         msgbox, Timed out waiting for clipboard access
         ; return or do something else
       }
       sleep, 100
       continue
     }
   }
;;;;;;;;;;;;;;;;; added code end
   If clipboard = %InvNum	; another program (or another part of your script) has opened the clipboard to put some data there
      { Sleep, 250 
      Send, ^c				; now, you want to paste that data into another program
      Continue 
      } 
   Else 
      { Break 
      } 
   }


Josh
  • Guests
  • Last active:
  • Joined: --
The thing is there is no paste. It is only trying to copy. The paste happens about 3 seconds before hand. Another paste wont happen until it either verifies the numbers it copied originally not to match or it continues the main loop to paste in the same location it did 3 seconds before hand.

Is there a way to do that script without any termination of the script? I need to be able to leave my script running unassisted and I do not want to have to restart it. So far I have had to press enter each time I get that message and it goes on.

  • Guests
  • Last active:
  • Joined: --

The thing is there is no paste. It is only trying to copy. The paste happens about 3 seconds before hand. Another paste wont happen until it either verifies the numbers it copied originally not to match or it continues the main loop to paste in the same location it did 3 seconds before hand.

Is there a way to do that script without any termination of the script? I need to be able to leave my script running unassisted and I do not want to have to restart it. So far I have had to press enter each time I get that message and it goes on.

Did you try the added code solution.? Did you get a time out msgbox?

Otherthan a solution like that, the only other way I know to 'fix' your problem is this (and it is a kludge). At the start of your primary script, start another script that will watch for the error message box, and have it click OK when it appears. It is not a pretty solution, but i WILL work. ;)

trenton_xavier
  • Members
  • 82 posts
  • Last active: Mar 16 2012 11:25 AM
  • Joined: 16 Jun 2008
Try using ClipWait after each time you copy in your code and try moving the clipboard into another var rather than reading straight from it.

Josh
  • Guests
  • Last active:
  • Joined: --
I added the code and after about 200 or so more loops I got the error message.

I am going to try and set it to sleep instead of popup and error message. The code made more sense after laying it out.

I have less than 150 more to do so idk if I will get the message again or not.

Hopefully having it sleep 250ms a message box wont show again.

Josh
  • Guests
  • Last active:
  • Joined: --
Well setting it to sleep instead has resulted in the entire script just stopping and no going anywhere when it gets to that point. I may end up going the other route of setting another script to run and press enter on the error message that pops up.

poo_noo
  • Members
  • 251 posts
  • Last active: Jan 28 2015 08:33 PM
  • Joined: 08 Dec 2006
Do you have a MS Remote Desktop session going ?? I have instances with AutoHotkey ( and other MS applications ) not being able to use the clipboard due to Rdpclip.exe.

<!-- m -->http://support.micro... ... -us;840872<!-- m -->

Just a thought.
Paul O

Josh
  • Guests
  • Last active:
  • Joined: --
The problem ended up being GoToAssist Express Expert running in the background. Even though I did not have a session running it still somehow caused the clipboard to be in use. I closed out of it any have not had a problem since.