In normal cases, go for keyup
:
$(document).keyup(function(e){
console.log(e.which);
});
Reasons:
keydown
keeps firing when user holds the keys down, whilekeypress
andkeyup
fire only once.keypress
doesn’t detect special keys (e.g.SHIFT
),keydown
andkeyup
do.