How to implement clipboard paste with Ctrl-V or button?

1,145 views
Skip to first unread message

Andrew de los Reyes

unread,
Jul 9, 2014, 1:39:16 PM7/9/14
to native-cli...@googlegroups.com
Hi Folks,

I have a NaCl/Chrome V2 app. I would like to implement copy and paste. I think copy will be doable in JavaScript (haven't tried yet), but I'm having trouble just getting paste to work. I know I need to handle this in JavaScript, but part of the problem is that I have NaCl set up to handle all keystrokes. So, when the user hits Ctrl-V, I get that in NaCl. Even if I return 'false' in the C++ event handler, the JavaScript onpaste doesn't seem to be called.

Are there any examples of a NaCl app that handles all keystrokes being able to handle paste?

Also, would it be possible to have a DOM/JS paste button (here I'm thinking about Chromebook touchscreen support where a keyboard may not be present or preferred)?

Thanks,
-andrew

Andrew de los Reyes

unread,
Jul 16, 2014, 11:20:57 AM7/16/14
to native-cli...@googlegroups.com
sbc@ told me to ping this thread. Does anyone have ideas?

I'm in building 1950, so if it's easier I can chat in person.

Ben Smith

unread,
Jul 16, 2014, 1:18:48 PM7/16/14
to native-cli...@googlegroups.com
Comments inline.

On Wednesday, July 16, 2014 8:20:57 AM UTC-7, Andrew de los Reyes wrote:
sbc@ told me to ping this thread. Does anyone have ideas?

I'm in building 1950, so if it's easier I can chat in person.

On Wednesday, July 9, 2014 10:39:16 AM UTC-7, Andrew de los Reyes wrote:
Hi Folks,

I have a NaCl/Chrome V2 app. I would like to implement copy and paste. I think copy will be doable in JavaScript (haven't tried yet), but I'm having trouble just getting paste to work. I know I need to handle this in JavaScript, but part of the problem is that I have NaCl set up to handle all keystrokes. So, when the user hits Ctrl-V, I get that in NaCl. Even if I return 'false' in the C++ event handler, the JavaScript onpaste doesn't seem to be called.

This is strange, as I ran the same test as you (on the input_event example in the SDK) and the onpaste event did fire. Here is my diff:

--- example.js
+++ example.js
@@ -5,6 +5,9 @@
 // Called by the common.js module.
 function moduleDidLoad() {
   common.naclModule.style.backgroundColor = 'gray';
+  document.body.onpaste = function(e) {
+    common.logMessage('onpaste called!');
+  };
 }
 
 // Called by the common.js module.

 --- input_event.cc
+++ input_event.cc
@@ -235,7 +235,7 @@
       } break;
     }
 
-    return true;
+    return false;
   }
 };
 
I'm ran this on Chrome 38.0.2081.0 on Linux, maybe it is broken on other OSes/older versions?


Are there any examples of a NaCl app that handles all keystrokes being able to handle paste?

Also, would it be possible to have a DOM/JS paste button (here I'm thinking about Chromebook touchscreen support where a keyboard may not be present or preferred)?

I believe you can do this with document.execCommand('paste'). See https://developer.chrome.com/extensions/declare_permissions#clipboardRead
 

Thanks,
-andrew

Andrew de los Reyes

unread,
Jul 16, 2014, 1:59:08 PM7/16/14
to native-cli...@googlegroups.com
Thanks. I'm able to reproduce your work on the demo and get the same results, but for some reason it doesn't work in my app when I seem to do the same thing. I wonder if it's because I'm using pnacl?

It's moot, though, because I think I can use the document.execCommand('paste') command to read the clipboard. So I can just run that when I detect Ctrl-V.

Thanks!

-andrew


--
You received this message because you are subscribed to a topic in the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/native-client-discuss/TW0HUKx7jCg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages