← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #170984]: Using the native getClipboard method in eclipse

 

Question #170984 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/170984

    Status: Open => Answered

RaiMan proposed the following answer:
no, this means, that you have to acquire the system clipboard only once
and then use it afterwards all over the place.

example (might not be error free, only to demonstrate):

Class MyClipboard:

protected Clipboard _cb = null

static {
   _cb = Toolkit.getDefaultToolkit().getSystemClipboard()
}
 
public static String getContent() {
      Transferable t = _cb.getContents(null);
      try {
        if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
          String text = (String) t.getTransferData(DataFlavor.stringFlavor);

          return text;
        }
      } catch (Exception e) {
      }
      return "";
    }
}

in your code:

MyClipboard cb = new MyClipboard(); # acquires the system clipboard once

System.out.println(cb.getContent()) # use cb as often you like

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.