We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
clipboard (Read 568 times)
clipboard
Nov 30th, 2007, 5:52pm
 
Anyone have a way to send text to the windows clipboard?

I've searched and found nothing that makes sense.
Re: clipboard
Reply #1 - Nov 30th, 2007, 6:12pm
 
Check out http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Toolkit.html#getSystemClipboard() and related links.

Please note that you can't use the clipboard in online applets without going through the process of using certificates to sign them.
Re: clipboard
Reply #2 - Nov 30th, 2007, 7:42pm
 
Thanks for the reply JohnG.

Unfortunately, java is not my first or second language!

I have seen: public abstract Clipboard getSystemClipboard()
but have know idea how to use it.

Regular sketch, nothing fancy. Just want to click the mouse on the screen and have it save some text to the clipboard.

Have a code snippet that will work for me?
Re: clipboard
Reply #3 - Aug 4th, 2008, 10:48am
 
HI,

Even if this post is pretty old, you can find a workaround there: http://workshop.evolutionzone.com/2006/08/29/code-copypastetoolpde/

On this basis, is it possible to send the content of a file (structured line by line) to the clipboard modifying this class ?

For example if the file contains;

line1
line2
line3
...

The clipboard will copy

line1
line2
line3
...

Thx
Re: clipboard
Reply #4 - Aug 4th, 2008, 11:23am
 
Good find, it looks like it wraps nicely the Clipboard.
To answer your question, I think you just have to read the file content in a string, then use sendString method.
Re: clipboard
Reply #5 - Aug 4th, 2008, 12:21pm
 
Hum, i already tried to concatenate each string of the file in one string.

The problem using that method is that pasting from the clipboard in the other application won't take carriage return in account.

So that, the clipboard will contain line1 line2 line3 ... and no

line1
line2
line3
...
Re: clipboard
Reply #6 - Aug 4th, 2008, 10:20pm
 
It depends on your platform, but on Windows I was successful by replacing the setup() in Marius' code by:

void setup() {
 copypaste = new CopyPaste();
 String[] lines = loadStrings("CopyPaste.pde");
 println(lines.length);
 String file = join(lines, "\r\n");
 copypaste.sendString(file);
}

where CopyPaste.pde was just the name of my sketch...

Perhaps more efficient would be to read the whole file at once, as a big string.
Re: clipboard
Reply #7 - Aug 5th, 2008, 4:59pm
 
Thx a lot,

I forgot that \r\n could came in handy in this case.

Merci Wink
a+
Page Index Toggle Pages: 1