Home > Back-end >  Chrome on android return everytime 229 for keyCode
Chrome on android return everytime 229 for keyCode

Time:09-17

I have this piece of code :

...
@HostListener('keydown', ['$event'])
onKeyDown(evt: KeyboardEvent) {
    console.log('KeyCode : '   evt.keyCode);
    console.log('Which : '   evt.which);
    ....
}

For ios checked all browsers --> working just fine

For android, is working on firefox, but on chrome I have 229 for evt.keyCode && evt.which, doesn't matter which key is pressed.

Have an idea about this problem ?

CodePudding user response:

Looks like keyCode is deprecated, and is still supported in some browsers for legacy reasons: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

Instead, it is recommended to use evt.code.

You should avoid using this if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code, if it's implemented. Unfortunately, some browsers still don't have it, so you'll have to be careful to make sure you use one which is supported on all target browsers.

Judging by the supported browsers table for the feature, you should be fine using key.

CodePudding user response:

evt.keyCode is deprecated, instead use evt.key which returns a String description of the key.

Nevertheless, it won't work on Chrome Android anyway, being a well known bug of the Chromium project.

It should work on Firefox Android.

  • Related