如何捕获触摸设备的屏幕键盘“keydown"和“keyup"事件 [英] How to capture the onscreen keyboard 'keydown' and 'keyup' events for touch devices

查看:37
本文介绍了如何捕获触摸设备的屏幕键盘“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
})

我希望 keydownkeyup 中定义的代码即使对于触摸设备(平板电脑和手机)也能触发.请建议如何捕获屏幕键盘事件并使上述代码运行.

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"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆