Recognize the 2 key from the keyboard or from the numpad
I would like to add keyboard short-cuts to my web application.
But for one of them, I need to be able to distinguish between the d开发者_StackOverflow中文版igits entered with the numpad from the one entered above the qwerty chars (my use case is for French keyboards, so it's azerty, but I don't think it's a problem). I'll combine it with a detection of the caps lock activation.
Is that possible?
Keycode detection is pretty chaotic in browsers: Check the quirksmode.org compatibility table.
According to this list, though, surprisingly to me, it seems in fact to be possible to distinguish the two:
Key Code
------------------------------
2 50
numpad 2 98
Haven't tried this but it's definitely worth a try.
Read up on keyCode
and the onkeyup
event.
document.onkeyup = alertKeyPressed;
function alertKeyPressed(){
var keyPressed = event.keyCode;
alert(keyPressed);
}
精彩评论