Search code examples
javascriptkeycode

How can I deal with different keyCodes on different browsers?


I've seen some forums posts about different browsers reporting different keyCodes, but everyone seems so avoid the "why?".

I was trying to capture the colon (:) keyCode and realized that Firefox reports back e.keyCode 56. While Chrome reports back 186 (I think that's what it was).

Is there a universal way of getting the right keyCode across all browsers?

And why are they different if they are the same keys?

I would be more curious as to whether there is a international way of getting the same key press.


Solution

  • See http://unixpapa.com/js/key.html for an explanation why they have different keys. I do not know of an international way to match keys.