1

Is there a jQuery plugin that normalizes key codes cross-browser? Meaning, if you press a certain key, then you are guaranteed to get the same key code for every browser that you test in?

Lester Peabody
  • 1,811
  • 3
  • 19
  • 42

2 Answers2

10

No, however, it is built into jQuery!

$("element").on("keypress",function(e){
    console.log(e.which);
});
Kevin B
  • 94,164
  • 15
  • 164
  • 175
3

The which property of the event object is defined for key and mouse events in most browsers, but not IE < 9. jQuery, however normalizes this support: e.which (Thanks @RocketHazmat for pointing this out)

$(this).keyup(function(e) {
    var code = e.which;
    ...
}
gen_Eric
  • 214,658
  • 40
  • 293
  • 332
benedict_w
  • 3,424
  • 1
  • 31
  • 48