Im using foloowing code to track key events
oEvent=window.event || oEvent;
iKeyCode=oEvent.keyCode || oEvent.which;alert(iKeyCode);
its
Here is a terse formulation:
document.onkeydown = function(e) {
switch (e.keyCode) {
case 37:
alert('left');
break;
case 38:
alert('up');
break;
case 39:
alert('right');
break;
case 40:
alert('down');
break;
}
};
However, if you are using JQuery, you are better off using e.which, which JQuery "normalizes" to account for cross-browser differences:
$(document).keydown(function(e) {
switch(e.which) {
// the rest is the same