eventsfirefoxkeydownnon-latin

Identification of non-latin characters by keydown


There is a problem in some browsers, for example, Firefox.

Code:

$(document).ready(function(){
     $(this).keydown(function(e){         // Or keyup or keypress
          alert(***look at output***);
     }
}

when typing non-latin characters as "<"-"б"-"Б" (russian) shows:

keydown    keyCode=0 which=0 charCode=0
keypress   keyCode=0 which=1073 charCode=1073 char=б
keyup      keyCode=0 which=0 charCode=0 

the same character in Chrome shows:

keydown    keyCode=188 which=188 charCode=0
keypress   keyCode=1073 which=1073 charCode=1073 char=б
keyup      keyCode=188 which=188 charCode=0

Problem: Identify keydown handler in all browsers, without using keypress (because of different charCodes on different keyboards layouts).


Solution

  • Solved, but with keypress. By listening keypress handle special for firefox bug, when with cyrillic keyboard layout doesn't work "<",">".

    Solution: on pressing keyboard button we listen keydown and keypress handels at the same time. If the cyrillic character pressed firefox keyCode output is 0 and keydown ignore it. On the other hand, keypress takes keyCode == 0 and makes an output "<" or ">".