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

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

推荐答案

您是否尝试使用按键代替key down

Have you tried using key press instead of key down

$("#id").keypress(function() {

});

更新:

由于安卓问题我现在通常像这样包裹我的支票

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天全站免登陆