Search code examples
javascriptfirefoxfirefox-addonfirefox-addon-sdk

Firefox addin sdk on launch/deploy check browser key bindings and warn if they are taken


Hello helpful internet people :)

I have been toying around with an the ff addon sdk and I have hit a snag. My addon will have an input box that will pop up and display when I hit Ctrl + T. My code does this fine in my non dev version ff because I have unbound the new tab binding(Ctrl + T).

    // Register key event handlers in each browser window
    var {observer} = require("sdk/keyboard/observer");
    var map = [];

    observer.on("keydown", function(event) {
        keylogger(event);
    });

    observer.on("keyup", function(event) {
        keylogger(event);
    });

    function keylogger(e){
        map[e.keyCode] = e.type == 'keydown';
        //console.log(e.keyCode); 
        if(map[17] && map[84]){ // maybe also check if the last key down was control.
            //console.log(map);
            // DO STUFF HERE!@
        };
    }

My issue is that when I hit this in the application that spawns from cfx run in console the binding is set. I assume its just a blank version of ff. I don't want to just unbind it for when im debugging the plan is that when someone gets the addon it will check if that binding exists and either prompt the user to unbind or just unbind. Does anyone know how to do this? Im not sure how to access the current keybindings. Is it possible?

Cheers for any help guidance or comments :)


Solution

  • I think the hotkey module overrides defaults. That said, the docs there pretty much echo my view:

    If you choose to use a key combination that's already defined, choose one which makes sense for the operation it will perform. For example, accel-S is typically used to save a file, but if you use it for something completely different then it would be extremely confusing for users.

    No matter what you choose, it's likely to annoy some people, and to clash with some other add-on, so consider making the combination you choose user-configurable.

    In this case, redefining accel-T is a really bad idea; it's probably the most used keyboard shortcut in any browser. I'm all for customizing your own setup, but distributing software with that shortcut seems crazy. Why not alt-T?