Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 428
user850234 Avatar asked Mar 30 '12 10:03

user850234


People also ask

What is Keyup Keydown and keypress?

The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress . An uppercase "A" is reported as 65 by all events.

Which event captures a keypress in JavaScript?

The onkeypress event occurs when the user presses a key (on the keyboard).

What is the difference between Keyup and Keydown?

The keydown event occurs when the key is pressed, followed immediately by the keypress event. Then the keyup event is generated when the key is released.


1 Answers

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;
}
like image 200
Dominic Green Avatar answered Oct 19 '22 14:10

Dominic Green