Answers.Body: <p>I'm not sure if there's an "official" way yet but I've looked through the source a little bit and I think the most Craft-like way I would do it, following plugin conventions, is to extend Garnish.Base with a new object that attaches the listener. </p>
  
  <pre><code>(function($) {
  
          var PluginName_KeyCapture = Garnish.Base.extend({
  
              init: function()
              {
                  this.addListener(Garnish.$doc, 'keydown', function(ev)
                  {
                      if ((ev.metaKey || ev.ctrlKey) &amp;&amp; ev.keyCode == 66)
                      {
                          ev.preventDefault();
                          console.log('You hit CTRL + B! Good work.');
                      }
                  });
              }
          });
  
          Craft.PluginName_KeyCapture = new PluginName_KeyCapture();
      })(jQuery);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-25T08:59:21.013Z
Answers.LastActivityDate: 2014-07-25T08:59:21.013Z
Answers.UserDisplayName: Mike Pepper
Body: <p>For example, when editing an entry <code>cmd + s</code> saves the entry. Is there an easy way to extend Garnish to allow for my plugin to listen for custom keyboard shortcuts?</p>
  
Tags: <plugin-development><javascript><garnish>
Title: Can Garnish be extended to allow plugins to use custom keyboard shortcuts?
ThreadText: # Can Garnish be extended to allow plugins to use custom keyboard shortcuts?
  
  (Asked by: username_0 on 2014-07-25)
  
  For example, when editing an entry `cmd + s` saves the entry. Is there an easy way to extend Garnish to allow for my plugin to listen for custom keyboard shortcuts?
  
  **Tags:** plugin-development, javascript, garnish
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-25. Score: 3
  
  I'm not sure if there's an "official" way yet but I've looked through the source a little bit and I think the most Craft-like way I would do it, following plugin conventions, is to extend Garnish.Base with a new object that attaches the listener.
  
  ```
  (function($) {
  
          var PluginName_KeyCapture = Garnish.Base.extend({
  
              init: function()
              {
                  this.addListener(Garnish.$doc, 'keydown', function(ev)
                  {
                      if ((ev.metaKey || ev.ctrlKey) && ev.keyCode == 66)
                      {
                          ev.preventDefault();
                          console.log('You hit CTRL + B! Good work.');
                      }
                  });
              }
          });
  
          Craft.PluginName_KeyCapture = new PluginName_KeyCapture();
      })(jQuery);
  
  ```
  
  
  ---
  
  