I am trying to change the keyboard shortcut for showing the context menu in Firefox (the equivalent of pressing Shift-F10 on Linux or Windows or Control-Space on OS X). It seems like this shortcut is handled at a different level from normal keyboard shortcuts (it doesn't show up in the Keyconfig extension that allows remapping of most keyboard shortcuts).
I have tried creating key and mouse events to trigger the context menu (using the following code that is mapped to a shortcut with Keyconfig) but they haven't worked so far. I haven't been able to track down where in the source code Firefox handles the keyboard shortcut for the context menu or if there is a single function that I could call to show it.
Mouse event:
var focused = document.commandDispatcher.focusedElement;
if(!focused) focused = document.commandDispatcher.focusedWindow.document.activeElement;
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 2, null);
focused.dispatchEvent(evt);
Key event:
var focused = document.commandDispatcher.focusedElement;
if(!focused) focused = document.commandDispatcher.focusedWindow.document.activeElement;
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, null, false, false, true, false, 0x79, 0);
focused.dispatchEvent(evt);