android上的keyCode总是229 [英] keyCode on android is always 229
问题描述
在我的三星Galaxy tab 4(Android 4.4.2,Chrome:49.0.2623.105)中,我遇到了keyCode始终为229的情况。
对于两种情况设置了一个简单的测试
< div contenteditable =true>< / div>
<输入>
< span id =keycode>< / span>
script:
< ('keydown',function(e){
$('#keycode')。html(e.keyCode);
})code> $('div,input')。 ;
幸运的是,我可以找到关于此的帖子,但我找不到有工作解决方案的帖子。有人建议使用 keyup
来代替或者使用 textInput
事件,但是只能在 blur
。
现在,最重要的是,这在默认的股票浏览器中不会发生:(
) b$ b
任何帮助将不胜感激!
更新:如果事实证明这是不可能的,我仍然可以在caret:帖子
正常的按键事件并没有在Android设备中给出keyCode。已经有一个很大的讨论。
如果你想捕获空格键
或特殊字符
,您可以使用 textInput
事件。 ('textInput',e => {$ b $($'$'$ $ $'$'$ $ $ $'$ $ $ $''$'$' b var keyCode = e.originalEvent.data.charCodeAt(0);
// keyCode是输入字符的ASCII码。
))
注意: textInput
不会触发字母,数字,退格,输入和其他几个键。
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.
这篇关于android上的keyCode总是229的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!