I have run the normal textbox in android device an i have face some issues which is mentioned below.
1.Keypress event does not triggered in android device 2.keycode value always return as 229 only
How to resolve this issue?
I have run the normal textbox in android device an i have face some issues which is mentioned below.
1.Keypress event does not triggered in android device 2.keycode value always return as 229 only
How to resolve this issue?
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 keyup
event.
$('#input').on('keyup', e => {
var keyCode = e.keyCode || e.which;
if (keyCode == 0 || keyCode == 229) {
keyCode = e.target.value.charAt(e.target.selectionStart - 1).charCodeAt();
}
})
just check your input characters keyCode, if it is 0 or 229 then here is the function getKeyCode which uses charCodeAt of JS to return the KeyCode which takes input string a parameter and returns keycode of last character.
<script>
var getKeyCode = function (str) {
return str.charCodeAt(str.length);
}
$('#myTextfield').on('keyup',function(e){
//for android chrome keycode fix
if (navigator.userAgent.match(/Android/i)) {
var inputValue = this.value;
var charKeyCode = e.keyCode || e.which;
if (charKeyCode == 0 || charKeyCode == 229) {
charKeyCode = getKeyCode(inputValue);
alert(charKeyCode+' key Pressed');
}else{
alert(charKeyCode+' key Pressed');
}
}
});
</script>