Question #244556 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/244556
RaiMan proposed the following answer: I think, this is a bug, but I did not yet dive into. feel free to report a bug (not necessary though) I set the whole ENV class as deprecated, since the function implementations have been moved to other locations, but are internally redirected for backward compatibility. the clipboard implementation is still the same as with RC3 and I had the impression, that it makes problems when used together with paste() in the same JVM session. Since you are programming in Java, there is no need to rely on the Sikuli feature: the Sikuli implementation (being now in class App) using java.awt.datatransfer together with the Toolkit.getDefaultToolkit().getSystemClipboard() So you might as well implement your own solution for a getClipboard. If you do, any findings would be helpful of course. this is the relevant coding: /** * evaluates the current textual content of the system clipboard * @return the textual content */ public static String getClipboard() { Transferable content = Clipboard.getSystemClipboard().getContents(null); try { if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) { return (String) content.getTransferData(DataFlavor.stringFlavor); } } catch (UnsupportedFlavorException e) { Debug.error("Env.getClipboard: UnsupportedFlavorException: " + content); } catch (IOException e) { e.printStackTrace(); } return ""; } /** * sets the current textual content of the system clipboard to the given text * @param text */ public static void setClipboard(String text) { Clipboard.putText(Clipboard.PLAIN, Clipboard.UTF8, Clipboard.BYTE_BUFFER, text); } private static class Clipboard { public static final TextType HTML = new TextType("text/html"); public static final TextType PLAIN = new TextType("text/plain"); public static final Charset UTF8 = new Charset("UTF-8"); public static final Charset UTF16 = new Charset("UTF-16"); public static final Charset UNICODE = new Charset("unicode"); public static final Charset US_ASCII = new Charset("US-ASCII"); public static final TransferType READER = new TransferType(Reader.class); public static final TransferType INPUT_STREAM = new TransferType(InputStream.class); public static final TransferType CHAR_BUFFER = new TransferType(CharBuffer.class); public static final TransferType BYTE_BUFFER = new TransferType(ByteBuffer.class); private Clipboard() { } /** * Dumps a given text (either String or StringBuffer) into the Clipboard, with a default MIME type */ public static void putText(CharSequence data) { StringSelection copy = new StringSelection(data.toString()); getSystemClipboard().setContents(copy, copy); } /** * Dumps a given text (either String or StringBuffer) into the Clipboard with a specified MIME type */ public static void putText(TextType type, Charset charset, TransferType transferType, CharSequence data) { String mimeType = type + "; charset=" + charset + "; class=" + transferType; TextTransferable transferable = new TextTransferable(mimeType, data.toString()); getSystemClipboard().setContents(transferable, transferable); } public static java.awt.datatransfer.Clipboard getSystemClipboard() { return Toolkit.getDefaultToolkit().getSystemClipboard(); } private static class TextTransferable implements Transferable, ClipboardOwner { private String data; private DataFlavor flavor; public TextTransferable(String mimeType, String data) { flavor = new DataFlavor(mimeType, "Text"); this.data = data; } @Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[]{flavor, DataFlavor.stringFlavor}; } @Override public boolean isDataFlavorSupported(DataFlavor flavor) { boolean b = this.flavor.getPrimaryType().equals(flavor.getPrimaryType()); return b || flavor.equals(DataFlavor.stringFlavor); } @Override public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (flavor.isRepresentationClassInputStream()) { return new StringReader(data); } else if (flavor.isRepresentationClassReader()) { return new StringReader(data); } else if (flavor.isRepresentationClassCharBuffer()) { return CharBuffer.wrap(data); } else if (flavor.isRepresentationClassByteBuffer()) { return ByteBuffer.wrap(data.getBytes()); } else if (flavor.equals(DataFlavor.stringFlavor)){ return data; } throw new UnsupportedFlavorException(flavor); } @Override public void lostOwnership(java.awt.datatransfer.Clipboard clipboard, Transferable contents) { } } /** * Enumeration for the text type property in MIME types */ public static class TextType { private String type; private TextType(String type) { this.type = type; } @Override public String toString() { return type; } } /** * Enumeration for the charset property in MIME types (UTF-8, UTF-16, etc.) */ public static class Charset { private String name; private Charset(String name) { this.name = name; } @Override public String toString() { return name; } } /** * Enumeration for the transfert type property in MIME types (InputStream, CharBuffer, etc.) */ public static class TransferType { private Class dataClass; private TransferType(Class streamClass) { this.dataClass = streamClass; } public Class getDataClass() { return dataClass; } @Override public String toString() { return dataClass.getName(); } } } -- You received this question notification because you are a member of Sikuli Drivers, which is an answer contact for Sikuli. _______________________________________________ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp