向 Firefox 扩展添加键盘快捷键

发布于 2024-12-22 12:28:54 字数 98 浏览 6 评论 0原文

我正在开发一个 Firefox 扩展。我在“工具”菜单中添加了一个新项目来打开我的扩展程序,但我想添加一个键盘快捷键来打开我的扩展程序(例如“control + alt + x”)。

I'm developing a Firefox Extension. I added a new item to the "Tools" Menu to open my extension, but I would like to add a keyboard shortcut to open my extension (something like 'control + alt + x').

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

禾厶谷欠 2024-12-29 12:28:54

如今,commands 键是执行此操作的好方法;例如,要切换主扩展弹出窗口(称为 browser_action),请在 manifest.json 中使用以下内容:

"commands": {
  "_execute_browser_action": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    }
  }
}

这还会在 Add- 中公开一个条目昂斯经理->管理扩展快捷键设置区域,用户可以在其中重新映射键盘快捷键。

在文档页面上阅读更多内容:
https://developer.mozilla.org /en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands

The commands key is a good way to do this these days; for instance to toggle the main extension pop up (known as the browser_action), use the following in manifest.json:

"commands": {
  "_execute_browser_action": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    }
  }
}

This also exposes an entry in the Add-ons Manager -> Manage Extension Shortcuts settings area where the user can re-map the keyboard shortcut.

Read more on the documentation page:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/commands

岁月流歌 2024-12-29 12:28:54

我自己找到了

<keyset id="mainKeyset"> <key id="key_convert" key="x" modifiers="accel alt" oncommand="OpenMyAddOn()"/> </keyset> 

I've found it by myself

<keyset id="mainKeyset"> <key id="key_convert" key="x" modifiers="accel alt" oncommand="OpenMyAddOn()"/> </keyset> 
因为看清所以看轻 2024-12-29 12:28:54

如果您需要在 Firefox 自带的菜单中添加快捷键来执行插件操作,那么您需要编辑
扩展名\content\firebug\firefox\browserMenu.js
并添加accesskey

    // Firefox page context menu
    $menupopupOverlay(doc, $(doc, "contentAreaContextMenu"), [
        $menuseparator(doc),
        $menuitem(doc,{
            id: "menu_ext",
            ....
            accesskey: "s"
        })
    ]);

If you need to add shortcut key to Firefox own menu to execute addon action, then you need to edit
extension\content\firebug\firefox\browserMenu.js
and add accesskey:

    // Firefox page context menu
    $menupopupOverlay(doc, $(doc, "contentAreaContextMenu"), [
        $menuseparator(doc),
        $menuitem(doc,{
            id: "menu_ext",
            ....
            accesskey: "s"
        })
    ]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文