Search code examples
ember.jsember-cli

EmberJS global keyPress


Does ember have a way to allow ember components to capture/listen to global keypress events without having to set focus (as described by the attached links)?

Is there an elegant way of doing this in the latest version on Ember ?

Global keyDown/keyPress events in EmberJS without having to set focus

Ember.js: View listening for keypress event


Solution

  • FYI best way to implement this is to use the Mousetrap.js http://craig.is/killing/mice

    Ember CLI instructions

    1. bower install --save mousestrap

    2. Add /* global Mousetrap */ to the top of the file you want to use mouse trap in (which in my case was a custom component

    3. Example usage:

      didInsertElement: function() {
       Mousetrap.bind('right', function() {
            alert('right direction arrow clicked');
          });
      }