Can menus have hotkey?

Hi!

If menu items are created with browser.menus.create such as here (not my project btw): https://github.com/cihanuygun/View-on-Same-Tab/blob/main/background.js

Is it possible to bind hotkey to such menu item so that user would not have to click?

Hi @wybqogzigoxruxdhnp and welcome to the community :wave:

It may be better to ask this in the “Add-Ons - Development” category.

In “normal” JavaScript you would listen on the Element: keydown event which also has boolean value to check if “CTRL”, “Alt” or “Shift” was additionally pressed. So you could check if “CTRL + a” was pressed for example.

I hope that helps.
Michael

Thought this was addon development. Could you link me correct category?

I moved your topic to the appropriate category.
“MDN” is the category about the web technology documentation https://developer.mozilla.org. So you weren’t far off. :slightly_smiling_face:

By the way: Your email address is visible in your post. It ended up in the optional “name” field of your profile. I recommend removing it.

Yes you can. To make a character work as “hotkey”, prefix that character with an “&” in the name of the menuitem.

Example setting the “X” in “View EXIF data” as hotkey:

browser.menus.create({
  id: "viewexif",
  title: "View E&XIF data",
  contexts: ["image"]
});

But I have no idea how Firefox handles it if several menuitems “claims” the same hotkey…

It will alternate focus between the two that shares the same key - try to right click your profile picture and press “o” to see it in action :slight_smile:.

Also I think Firefox automatically tries to assign fist letter as the hotkey - unless it’s already used. I’ve noticed it in some of my addons where it works even without me specifying it.

Thanks. That’s why I don’t use my real email to signup - because I never know how sites behave with my email by default.

Can I also override existing key?

This is what it does. Can I do anything tell FF that hey, I want my addon to replace built in menu item and I want my addon to handle this hotkey instead of default handler?