Theme / Language
UI Language UI言語
🔤
English
🎌
日本語
⚠️Each articles themselves will not be translated by this setting. Some of article has translation and some of them doesn't. You will notice if the article has its translation by its preamble!
⚠️記事自体は翻訳されません! 記事によって英語版があったりなかったりします。翻訳がある記事は文頭に記載があるよ!
Theme テーマ
😎
Wakey Wakey
オハヨー
🌚
Go dark
ダークモード
🦹‍♂️
I'm not a comic-book villain
私は漫画本の悪役とは違う

Processing: Copy a text string to clipboard

2020-01-31
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.

1
import java.awt.datatransfer.Clipboard;
2
import java.awt.datatransfer.Transferable;
3
import java.awt.datatransfer.StringSelection;
4
import java.awt.Toolkit;
5
6
void CopyToClipboard(String s)
7
{
8
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
9
	StringSelection data = new StringSelection(s);
10
	clipboard.setContents(data, data);
11
}

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

References🙇