Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a Keyboard Shortcut to Firefox Extension

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').

like image 840
Dante López Avatar asked Dec 21 '11 21:12

Dante López


People also ask

How do I create a keyboard shortcut for an extension?

Open the More Tools menu. Select Extensions. In the upper left corner, click on the hamburger icon and select Keyboard Shortcuts. Find the desired extension and press a combination of “Ctrl” or “Ctrl + Shift” and any other available key.

How do I create a shortcut key in Firefox?

Video: Make custom Firefox shortcuts and gesturesStep 2: Click on the orange Firefox button, then Options. Step 3: Click on the last tab called Shortcuts. Step 4: Double-click on the shortcut you want to customize, then type in the key combination you prefer to use.

How do I add an extension button to my toolbar in Firefox?

Click on Customize Toolbar. Firefox will open a new page with a list of items that you can drag into the toolbar. Look for Add-ons and themes. Click on Add-ons and themes and drag it into your toolbar.


2 Answers

I've found it by myself

<keyset id="mainKeyset"> <key id="key_convert" key="x" modifiers="accel alt" oncommand="OpenMyAddOn()"/> </keyset> 
like image 138
Dante López Avatar answered Oct 04 '22 16:10

Dante López


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

like image 21
kjones Avatar answered Oct 04 '22 15:10

kjones