How do I detect when one of the arrow keys are pressed? I used this to find out:
function checkKey(e) {
var event = window.event ? window.event : e;
console.log(event.keyCode)
}
Though it worked for every other key, it didn't for arrow keys (maybe because the browser is supposed to scroll on these keys by default).
I've been able to trap them with jQuery:
An example: http://jsfiddle.net/AjKjU/
That's shorter.
function IsArrows (e) { return (e.keyCode >= 37 && e.keyCode <= 40); }
That is the working code for chrome and firefox
I was also looking for this answer until I came across this post.
I've found another solution to know the keycode of the different keys, courtesy to my problem. I just wanted to share my solution.
Just use keyup/keydown event to write the value in the console/alert the same using
event.keyCode
. like-- rupam
control the Key codes
%=37
and&=38
... and only arrow keys left=37 up=38On key up and down call function. There are different codes for each key.