Copy text to clipboard

How can I copy a String to Clipboard (similar to Clipboard’s setContent() in java)?

1 Like


processing is java. So you can use the same classes. Here is an adapted sketch from an example from this page.

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

void setup() {
  StringSelection selection = new StringSelection("some text");
  Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  clipboard.setContents(selection, selection);


@Alex_Pr , @benja ===
Android is java, yes, but it has its own world and in this world i dont think that the code put by @benja can work… For doing that you have to use android ClipboardManager. More details here:

where can I find those libraries?

awt ist part of java, so no need to download anything.
you can just run the example above in processing, then “some text” is copied to your clipboard.

but no idea about android …

See here.

1 Like

@Malsvir I expanded it a bit here.