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?


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)
                        console.log('You hit CTRL + B! Good work.');

        Craft.PluginName_KeyCapture = new PluginName_KeyCapture();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.