How to capture the onscreen keyboard #39;keydown#39; and #39;keyup#39; events for touch devices(如何捕获触摸设备的屏幕键盘“keydown和“keyup事件)
问题描述
我已经定义了在桌面上运行良好的键盘事件,但对于没有获得屏幕键盘事件的触摸设备.如果用户正在输入,我需要捕获.我使用了以下代码段:
I have defined keyboard events which is working good in desktop but for touch devices not getting the onscreen keyboard event. I need to capture if user is typing. I have used the following segment of code :
$('#id').keydown(function(e){
//some code here
});
$('#id').keyup(function(e){
//some code here
})
我希望 keydown
和 keyup
中定义的代码即使对于触摸设备(平板电脑和手机)也能触发.请建议如何捕获屏幕键盘事件并使上述代码运行.
I want the code defined in keydown
and keyup
to trigger even for touch devices (both tablets and mobiles). Please suggest how to capture the onscreen keyboard event and make the above code to run.
推荐答案
你试过用按键代替按键吗
Have you tried using key press instead of key down
$("#id").keypress(function() {
});
更新:
由于 android 的问题,我现在通常像这样包装我的支票
Due to android problems I now normally wrap my checks like this
if ($.browser.mozilla) {
$("#id").keypress (keyPress);
} else {
$("#id").keydown (keyPress);
}
function keyPress(e){
doSomething;
}
这篇关于如何捕获触摸设备的屏幕键盘“keydown"和“keyup"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何捕获触摸设备的屏幕键盘“keydown"和“keyup"事件


基础教程推荐
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01