问题
Is there a way to disable keyboard shortcuts (hotkeys) in a firefox add-on?
回答1:
If your addon has an overlay for browser.xul, an alternative to handling the "keypress" event is to use script in the "load" handler to remove the relevant elements from the browser XUL document like this:
var key = document.getElementById("key_openDownloads");
key.parentNode.removeChild(key);
In case it's not obvious, this removes the hotkey for opening the download manager. You can see all the keys here: http://mxr.mozilla.org/mozilla2.0/source/browser/base/content/browser-sets.inc. This is for Mozilla 2.0 (i.e. Firefox 4.0.x). You can change the tree using the dropdown at the top of the page, but I don't think these keys or their IDs change very often anyway.
Depending on your use case, this might be more convenient than catching "keypress".
来源:https://stackoverflow.com/questions/6437121/disabling-hotkeys-in-firefox-addon