1

I have this code that I have made to handle the CTRL+V from the browser, works fine however I need to get the clipboard data like this:

    Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
        @Override
        public void onPreviewNativeEvent(Event.NativePreviewEvent event)
        {
            NativeEvent ne = event.getNativeEvent();
            // When CTRL + V is pressed
            if (event.getNativeEvent().getKeyCode() == 86 && // 'V'
                    event.getNativeEvent().getCtrlKey() == true) {
                // need to get the clipboard data
            }
        }
    });
quarks
  • 33,478
  • 73
  • 290
  • 513

2 Answers2

1

JavaScript per se does not allow to simply read the system clipboard as this would be a huge security risk. Most browsers do, however, provide the means to achieve this (although it has to be enabled by the user). The API is, thus, browser dependend. For Firefox have a look at https://developer.mozilla.org/en-US/docs/Using_the_Clipboard.

To the best of my knowledge there is na GWT specific wrapper of this functionality. Thus, you need to work with GWT JSNI (http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html)

Arno Mittelbach
  • 952
  • 5
  • 12
-1

Although I'm the one that marked this question as a duplicate, I think the answers in that question may be bit out of date. When I google, I find this discussion. The answers in there solve the problem with JSNI but they remark that it doesn't work in FF because FF requires manually enabling restrictions. If this doesn't help, you may have to use the answers in the duplicate.

Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356
  • 1
    The discussion is similar to my question but those are quite about copying to the clipboard, mine is copying the clipboard data – quarks Sep 03 '13 at 18:49