Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect CTRL+V in javascript with Cyrillic layout?

I detect ctrl+v in keydown event in such a way:

.keydown(function(e){
   if ( e.ctrlKey && e.keyCode == 86 ) {
      console.log ('ctrl+v!');
   }
});

it works fine, when my layout is latin (English). But when I switch my layout to Russian (cyrillic) - ctrl+v is executed (text is inserted) but jQuery detection doesn't work. (e.keyCode = 0 of cyrillic symbols).

P.S. I need it in good order (for preformatting inserted text )

P.P.S. My task was accomplished without detection of pasting. (just listening on keyup event was enough for me), but the problem exist on my PC (Ubuntu, Fx6). keyCode of Cyrillic symbols is recognized as 0, and you can't detect shortcuts with latin letters (ctrl+c,ctrl+v, etc).

like image 962
Larry Cinnabar Avatar asked Aug 12 '11 22:08

Larry Cinnabar


1 Answers

This works fo me on ubuntu too(FF 5):

.keypress(function(e){
    if ( e.ctrlKey && (e.which == 86 || e.which==118) ) {
      console.log ('ctrl+v!');
   }
});

for ctrl+n use

 if ( e.ctrlKey && (e.which == 110 || e.which==78) ) 

and for ctrl+t:

if ( e.ctrlKey && (e.which == 84 || e.which==116) )
like image 119
Dr.Molle Avatar answered Oct 02 '22 15:10

Dr.Molle