Capture Windows Clipboard with JAVA

Asked

Viewed 862 times

3

There is how to capture the Clipboard in Windows environment with Java?

I can capture the screen, but I would like to capture the Clipboard (that’s what stays in memory when doing CTRL+C, for example).

A simple tip is enough for me.

1 answer

5

Yeah, you can use the class Toolkit. Here’s an example:

import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

String data = (String) Toolkit.getDefaultToolkit()
                .getSystemClipboard().getData(DataFlavor.stringFlavor);

The method getData() and the stringFlavor return plain text from Clipboard.

More information:

  • Thanks, I’ll give it a study and anything I ask.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.