$(document).ready(function(){
  $(document).keydown(function(e) {
    var target = e.target || e.srcElement;
    var nodeName = target.nodeName.toLowerCase();
    // if key is pressed while focussed in an input, don't do anything
    if (nodeName == "input" || nodeName == "textarea") { return; }
    switch(e.which) {
      // user presses the "p"
      case 65: if($(".west a").attr("href")) { window.location = $(".west a").attr("href") };
        break;
      // user presses the "n" key
      case 68: if($(".east a").attr("href")) { window.location = $(".east a").attr("href") };
        break;
      // user presses the "u" key
      case 87: if($(".north a").attr("href")) { window.location = $(".north a").attr("href") };
        break;
      // user presses the "d" key
      case 83: if($(".south a").attr("href")) { window.location = $(".south a").attr("href") };
        break;
    }
  });
});