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);
});
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
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.