Stable
Assign Hotkey combinations to functions in your add-on.
Usage
To define a hotkey combination, create a Hotkey
object, passing it the combination and a function to be called when the user presses that combination. For example, this add-on defines two hotkey combinations, to show and hide a panel:
// Define keyboard shortcuts for showing and hiding a custom panel. var { Hotkey } = require("sdk/hotkeys"); var showHotKey = Hotkey({ combo: "accel-shift-o", onPress: function() { showMyPanel(); } }); var hideHotKey = Hotkey({ combo: "accel-alt-shift-o", onPress: function() { hideMyPanel(); } });
Choosing Hotkeys
All Hotkey combinations require atleast one modifer-key+ (Control+key, Shift+key, Alt+key, Option+key, Command+key) or the following type error will occcur: "Hotkey must have at least one modifier"
Hotkey selection should be choosen with care. It's very easy to overwrite other combinations that clash with hotkeys defined for Firefox or for other add-ons: Please reference the Firefox Keyboard shortcuts page for already used shortcuts.
Due to the nature of mainstream hotkey combinations already in heavy use the following Hotkeys will not pass the AMO Add-on review:
accel-Z, accel-C, accel-X, accel-V or accel-Q
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.
Globals
Constructors
Hotkey(options)
Creates a hotkey whose onPress
listener method is invoked when key combination defined by hotkey
is pressed.
If more than one hotkey
is created for the same key combination, the listener is executed only on the last one created.
Parameters
options : Object
Required options:
Name | Type | |
---|---|---|
combo | String |
Any function key: "accel-s" "meta-shift-i" "control-alt-d" Modifier keynames:
|
onPress | Function |
Function that is invoked when the key combination |
Hotkey
Module exports Hotkey
constructor allowing users to create a hotkey
for the host application.
Methods
destroy()
Stops this instance of Hotkey
from reacting on the key combinations. Once destroyed it can no longer be used.