Keycode is always zero in Chrome for Android Keycode is always zero in Chrome for Android google-chrome google-chrome

Keycode is always zero in Chrome for Android


below solution also work for me. might be useful for others also.

var getKeyCode = function (str) {    return str.charCodeAt(str.length - 1);}document.getElementById("a").onkeyup = function (e) {    var kCd = e.keyCode || e.which;    if (kCd == 0 || kCd == 229) { //for android chrome keycode fix        kCd = getKeyCode(this.value);    }    alert(kCd)}


I faced this issue and this is how I figured out how to solve the problem.

  • First, you need to enable USB debugging onto your Android phone soyou can see the logs of your browser on your desktop machine.
  • Second, refresh your web app on your phone and inside your console on the desktop type "monitorEvents(document)" or whatever element you want to inspect.
  • Do the action you want to inspect on your phone.

And this is how I found that the keydown event was actually fired by a unique event called "textInput" which contains the information inside event.originalEvent.data.

Hope this saves you time and good luck!


We encountered this problem recently on a China made Android phone Meizu MX3, which has a deeply customized OS based on Android 4.4.4.

The default browswer and Chrome work just fine, but for some weird reasons we don't know, event.keyCode, event.charCode and event.which return 0 all the time in some other browsers(such as CM Browser or webview of Wechat app).

We resolved this by checking the last character you input such as 'A' or ' '(space), then we convert it to ascii code using charCodeAt such as "A".charCodeAt(0) which returns 97, which is the actual char code we need.

But we can only determine the char code of visible chars using this strategy, which meets our current need thank god.

Hope you guys can get some inspiration from this.