JavaScript

jQuery: keyup, keydown, keypress?

In normal cases, go for keyup:

$(document).keyup(function(e){
  console.log(e.which);
});

Reasons:

  1. keydown keeps firing when user holds the keys down, while keypress and keyup fire only once.
  2. keypress doesn’t detect special keys (e.g. SHIFT), keydown and keyup do.
Standard