Loading...
Logo
Processing Forum
Is there a way to have text saved on a user's clipboard to be pasted into a processing sketch.

What I'm trying to do is allow someone to paste their facebook url into a processing sketch and it to return some user data using the facebook API.

When I create a sketch that allows for keyboard input it doesnt recognize command v and the menu bar paste option is grayed out. 

It probably has to be something along the lines of

if ( key v &command key==true){
put contents of clipboard into string and display on screen
}

Suggestions!?!?

Replies(1)

I use this to set the contents of the clipboard.. so I expect it would be similar to get the contents.
Copy code
  1. void clip(String cliptext) {
  2.   //Get the toolkit
  3.   Toolkit toolkit = Toolkit.getDefaultToolkit();
  4.   //Get the clipboard
  5.   Clipboard clipboard = toolkit.getSystemClipboard();
  6.   //The setContents method of the Clipboard instance takes a Transferable
  7.   //as first parameter. The StringSelection class implements the Transferable
  8.   //interface.
  9.   StringSelection stringSel = new StringSelection(cliptext);
  10.   //We specify null as the clipboard owner
  11.   clipboard.setContents(stringSel, null);
  12. }