Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keyCode on android is always 229

On my Samsung Galaxy tab 4 (Android 4.4.2, Chrome: 49.0.2623.105) I ran into a situation where the keyCode is always 229.

I've setup a simple test for two situation

<div contenteditable="true"></div> <input> <span id="keycode"></span> 

script:

$('div, input').on('keydown', function (e) {     $('#keycode').html(e.keyCode); }); 

DEMO

Fortunately I can find posts about this, but I couldn't find one with a working solution. Someone suggested to use keyup instead or to use the textInput event, but that one is only fired on blur.

Now, to top it all, this doesn't happen with the default stock browser :(

Any help would be appreciated!

UPDATE: If it turns out that this is not possible I can still grab the char before the caret: post

like image 941
Jeanluca Scaljeri Avatar asked Apr 20 '16 19:04

Jeanluca Scaljeri


People also ask

What is the keyCode for period?

According to the website, key-code for . is 190. I've experienced the same, got 46 for dot .

What is keyCode in keyboard?

Key codes are numeric values that correspond to physical keys on the keyboard but do not necessarily correspond to a particular character.


1 Answers

Normal keypress event does not give keyCode in android device. There has already been a big discussion on this.

If you want to capture the press of space bar or special chars, you can use textInput event.

$('input').on('textInput', e => {      var keyCode = e.originalEvent.data.charCodeAt(0);      // keyCode is ASCII of character entered. }) 

Note: textInput does not get triggered on alphabets, number, backspace, enter and few other keys.

like image 197
Imamudin Naseem Avatar answered Sep 23 '22 00:09

Imamudin Naseem