If you want to trigger and event of “keydown” or “keyup” using a browser coming from an Android device be aware that Android will always send the keyCode = 229 and so you are not able to use that data in the standard way

Example

/* user press "a" button */
document.getElementById('yourID').addEventListener('keydown', function(e){
 console.log(e.keyCode); //expected 65 got 229
 console.log(e.key); //expected "a" got "Unidentified"
});

To avoid this problem I’d suggest you to use “textInput”

/* user press "a" button */
document.getElementById('yourID').addEventListener('textInput', function(e){
 console.log(e.data); //a
});

Be prepared that “textInput” does not trigger some special event like “backspace…”

Here a good test environment with examples https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key

Pressing “a” key via chrome browser you get

Key “a” pressed [event: keydown]
Key “a” about to be input [event: beforeinput]
Key “a” input [event: input]
Key “a” released [event: keyup]

Pressing “a” key via chrome android browser you get

Key “Unidentified” pressed [event: keydown]
Key “a” about to be input [event: beforeinput]
Key “a” input [event: input]
Key “Unidentified” released [event: keyup]

Categories: Js,Ts,Css

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published.