Search code examples
user-interfacefirefoxfirefox-addon-sdkhotkeys

How to allow user to configure hotkeys in my firefox addon


Maybe it's in some manual page somewhere, but my Googling skills certainly fail me to find the answer or at least compose right query.

I am authoring a Firefox extension and I want to bind certain action to hotkey. Now, hardcoding hotkeys is one of the worst UX things you can do, so I want hotkey to be user-configurable.

There's a well-written page about making hotkeys in addons: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/hotkeys Hotkey is specified as string in some specific format. There's another well-written page about how to set preferences for addons here: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/simple-prefs

But what is the user-friendly way to specify hotkeys in my preferences? Am I limited to string input which forces users to use the hotkey spec format listed in the hotkey module reference above?

This must be the already solved task, I expect that there's a manual somewhere. The UI control allowing to capture key combinations is already existing in all operation systems.


Solution

  • The following related question has an answer.

    The solution is based on using the special button after click on which we'll start listening for keypress events and thus capturing whatever user input on a keyboard. After capturing we can generate the hotkey definition string according to rules of hotkey module and everything'll be well.

    A place to put this button on is needed, though.