Sunday, November 10, 2013

Check to see if an arrow key has been pressed in JavaScript!

Stealing this from here:

<script type="text/javascript">
   $(function () {
      document.onkeydown = function () {
         switch (window.event.keyCode) {
            case 37:
               alert('left');
               break;
            case 38:
               alert('up');
               break;
            case 39:
               alert('right');
               break;
            case 40:
               alert('down');
               break;
         }
      };
   });
</script>

No comments:

Post a Comment