How to capture the onscreen keyboard 'keydown' and 'keyup' events for touch devices

31,894

Have you tried using key press instead of key down

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

});

Updated :

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;
}
Share:
31,894
user850234
Author by

user850234

Updated on August 22, 2022

Comments

  • user850234
    user850234 over 1 year

    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
    })
    

    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.

  • Dominic Green
    Dominic Green about 10 years
    This is a pretty old answer now, I think recently I have come across this problem and have solved it for now by doing a simple check. I have updated my answer see if that works, let me know how you get on.
  • px5x2
    px5x2 over 8 years
    $.browser deprecated and removed in jq 1.9.
  • Herbert Van-Vliet
    Herbert Van-Vliet about 2 years
    I am using vue3, and it seems keyup fires, but keypress does not (Android 9, Chrome 88.0.4324.181). If your situation is like mine and you're using the events to do some form of validation or evaluation, the solution could be to rethink the requirements and combine the functions.