Copy text to clipboard

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

1 Like

Hey,

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);
  exit();
}

Regards.

@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: https://developer.android.com/guide/topics/text/copy-paste