admin管理员组文章数量:1315940
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?
Share Improve this question asked Aug 19, 2016 at 9:17 Roy thomasRoy thomas 1151 gold badge1 silver badge10 bronze badges 4- 2 Possible duplicate of Capture keys typed on android virtual keyboard using javascript – billyonecan Commented Aug 19, 2016 at 9:33
- Hi billyonecan Same issue is for me,Thanks But i cant find any solution from that.Can you please explain what solution is given there? – Roy thomas Commented Aug 19, 2016 at 9:54
- You can check this stackoverflow./questions/25043934/… – flymaxelib Commented Sep 8, 2021 at 8:46
- Try in Firefox browser in Android devices. – Nice Books Commented Sep 8, 2021 at 10:16
2 Answers
Reset to default 4Normal 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>
本文标签: javascriptKeycode value is return as 229 for all keysStack Overflow
版权声明:本文标题:javascript - Keycode value is return as 229 for all keys - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741995871a2410033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论