title: angular.js listen for keypress as shortcut for button
body: <p>My first ever angular application is a pretty basic survey tool. I have multiple choice questions, with a button for each answer and a basic function that logs each answer on button click like this:</p>
  
  <pre><code>ng-click="logAnswer(answer.id)"
  </code></pre>
  
  <p>What I'm looking for is to be able to add a keypress event to the document that will listen for a keyboard response of 1, 2, 3, 4, 5 which matches up with the button choices and calls the same function.</p>
  
  <p>In searching around I can only find responses that relate to keypresses once a particular input field has focus, which doesn't help me. I did find the OPs response on this post <a href="https://stackoverflow.com/questions/20986240/angular-js-keypress-events-and-factories">Angular.js keypress events and factories</a> which seems to be heading in the right direction, but I just can't work out how I get his directive to call my function.</p>
  
  <p>I've included the directive in my js:</p>
  
  <pre><code>angular.module('keypress', []).directive('keypressEvents', 
    function($document, $rootScope) {
      return {
        restrict: 'A',
        link: function() {
          $document.bind('keypress', function(e) {
             $rootScope.$broadcast('keypress',e , String.fromCharCode(e.which));
          });
       }
     }
  })
  </code></pre>
  
  <p>but I'm not sure how I make use of the keybinding object within my controller:</p>
  
  <pre><code>function keyedS(key, parent_evt, evt){
        // key is the key that was pressed
        // parent_evt is the keypress event
        // evt is the focused element object
  }
  $scope.keyBindings = {
      's': keyedS
  }
  </code></pre>
  
  <p>How do I make the keybinding object listen for the keys I'm listening for and fire-off the function that I need?</p>
  
  <p>thanks</p>