Add a Keyboard Shortcut to Firefox Extension
Asked Answered
E

3

11

I'm developing a Firefox Extension. I added a new item to the "Tools" Menu to open my extension, but I would like to add a keyboard shortcut to open my extension (something like 'control + alt + x').

Exurb answered 21/12, 2011 at 21:34 Comment(2)
I've found it by myself <keyset id="mainKeyset"> <key id="key_convert" key="x" modifiers="accel alt" oncommand="OpenMyAddOn()"/> </keyset>Cranage
See also: developer.mozilla.org/en/XUL_Tutorial/Keyboard_ShortcutsScotsman
E
7

I've found it by myself

<keyset id="mainKeyset"> <key id="key_convert" key="x" modifiers="accel alt" oncommand="OpenMyAddOn()"/> </keyset> 
Exurb answered 23/12, 2011 at 14:31 Comment(0)
C
8

The commands key is a good way to do this these days; for instance to toggle the main extension pop up (known as the browser_action), use the following in manifest.json:

"commands": {
  "_execute_browser_action": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    }
  }
}

This also exposes an entry in the Add-ons Manager -> Manage Extension Shortcuts settings area where the user can re-map the keyboard shortcut.

Read more on the documentation page: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands

Criticize answered 2/3, 2021 at 6:57 Comment(1)
This is the true answer.Midwifery
E
7

I've found it by myself

<keyset id="mainKeyset"> <key id="key_convert" key="x" modifiers="accel alt" oncommand="OpenMyAddOn()"/> </keyset> 
Exurb answered 23/12, 2011 at 14:31 Comment(0)
M
0

If you need to add shortcut key to Firefox own menu to execute addon action, then you need to edit extension\content\firebug\firefox\browserMenu.js and add accesskey:

    // Firefox page context menu
    $menupopupOverlay(doc, $(doc, "contentAreaContextMenu"), [
        $menuseparator(doc),
        $menuitem(doc,{
            id: "menu_ext",
            ....
            accesskey: "s"
        })
    ]);
Moslem answered 19/2, 2016 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.