I tried with keydown and keypress but both fire constantly if the user holds a key. Is there a way to listen only for the when the user presses the key (changes from not pressed to pressed) so that eg: holding the key fires the code once and pressing it, releasing it and pressing it again 2 times?
This is what I’m using to check which keys are down:
$(document).keydown(function (e){
console.log(e.which);
});
You could, on the first call of
keydown, unbind thekeydownhandler and then rebind it onkeyup.http://jsfiddle.net/cbSRu/2/