Processing: Copy a text string to clipboard

Processing Copy String to Clipboard

I’m starting to try Processing, which is a program language… or a IDE? Graphic tool? I’m struggling with the syntax like I always forget “; semi-colon“, since the language I was using lately is Python for blender script. But it’s fun like I could make a tool for my own even it was my very first day of Processing 3.

§

I thought it is only for graphic processing, but actually it has some affinity to OS itself. It can copy a string to system’s clipboard.

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.StringSelection;
import java.awt.Toolkit;

void CopyToClipboard(String s)
{
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection data = new StringSelection(s);
	clipboard.setContents(data, data);
}

The code above worked on my Windows 10. It uses the ancient Java (not a script), how nostalgy.

§

References🙇

Paste and Copy text – Processing 2.x and 3.x Forum
https://forum.processing.org/two/discussion/27473/paste-and-copy-text

What is the simplest way to copy to the clipboard from processing? – Processing Forum
https://forum.processing.org/one/topic/what-is-the-simplest-way-to-copy-to-the-clipboard-from-processing#25080000000067184.html

コメントを残す

メールアドレスが公開されることはありませんし、空欄で大丈夫です。っていうかコメント以外空欄で良いです。気軽にコメントして下さい。
Email won't be published. Or you can leave it blank. I mean you can leave everything blank but comment. Feel free to leave a comment, thanks.