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,868
  • 3
  • 20
  • 42

2 Answers2

10

No, however, it is built into jQuery!

$("element").on("keypress",function(e){
    console.log(e.which);
});
Kevin B
  • 94,570
  • 16
  • 163
  • 180
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
  • 223,194
  • 41
  • 299
  • 337
benedict_w
  • 3,543
  • 1
  • 32
  • 49