Firefox onkeypress with Ctrl key

I have an input on which I want specific behavior when a character is inserted, but I want the default behavior to be on shortcuts like ctrl+ cand ctrl+ v.

Here's the html:

<input type="text" onkeypress="onInputKeyPress(event)" />

and javascript:

function onInputKeyPress(event) {
    if (event.charCode >= 32) {
        // do some processing here       
        event.preventDefault();
    }
}

This works fine in IE and Chrome, but not in Firefox. This is because when I use ctrl+ cor ctrl+ v, onkeypressit is not called in IE and Chrome, but it calls the call in Firefox.

So, I tried to insert this code at the beginning of my handler:

if (event.ctrlKey) {
    // leave default behavior for shortcuts
    return true;
}

Now my custom processing is not called when I press ctrl+ c, but the shortcut still does not work (the text is not copied to the clipboard).

- , Firefox ?

+4
1

, , , :

:

var clipboard = require("sdk/clipboard");
clipboard.set("Lorem ipsum dolor sit amet");
var contents = clipboard.get();

: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/clipboard

0

All Articles