views:

28

answers:

2

Hi,

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 digits 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?

Thnaks.

+5  A: 

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.

Pekka
I think that will do. Thanks! ;)
Savageman
A: 

Read up on keyCode and the onkeyup event.

document.onkeyup = alertKeyPressed;       

function alertKeyPressed(){
     var keyPressed = event.keyCode;
     alert(keyPressed);
}
HurnsMobile