javascript - 键盘快捷键扩展中的触发事件

标签 javascript google-chrome google-chrome-extension macros

我的 friend 向我提出挑战,要求我找出一种从计算机桌面(或与 Chrome 不同的程序)控制 YouTube(在 Chrome 中)的方法。基本上,这里的想法是触发一个事件,让我可以处理如何使用某些热键组合。 Chrome has an api (chrome.commands) 允许这样做,但用户必须在 chrome 中才能触发该事件(这是有道理的)。我想讨论任何可能的替代方案。

我知道扩展程序可以对计算机进行文件访问(使用 chrome.fileSystem api ),所以我正在考虑在某个地方有一个文件夹,其中包含要写入的文本文件通过在用户计算机上运行的脚本来实现。该脚本也可能只是 Windows 在某个击键时触发的宏。

这是一种实用的方法,还是有更简单的方法来实现这一目标?似乎需要很多“移动”部件才能完成这项工作。

编辑:这里的主要目标是让跳过和暂停/播放键(某些键盘具有)与 Chrome 一起使用。使用 Ctrl+Shift+[0-9] 可以与 chrome.commands 配合使用,但是有人还有其他建议让其他键正常工作吗?

最佳答案

chrome.commands 有一组非常有限的全局快捷键:

By default, Commands are scoped to the Chrome browser, which means that while the browser does not have focus, the shortcut will be inactive. On desktop Chrome, Commands can instead have global scope, as of version 35, and will then also work while Chrome does not have focus. NOTE: The exception here is Chrome OS, where global commands are not allowed at the moment.

The user is free to designate any shortcut as global using the UI in chrome://extensions \ Keyboard Shortcuts, but the extension developer is limited to specifying only Ctrl+Shift+[0..9] as global shortcuts. This is to minimize the risk of overriding shortcuts in other applications since if, for example, Alt+P were to be allowed as global, the printing shortcut might not work in other applications.

文档可用 here .

关于javascript - 键盘快捷键扩展中的触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45463916/

相关文章:

google-chrome - 将 Chrome 中的 console.log 保存到文件中

javascript - 全局变量 Chrome 扩展内容脚本

javascript - 当我点击时 Chrome.storage.onChanged 存储 newValue

javascript - React Native/Firebase 格式错误

c - 在 Chrome 的 NPAPI 窗口插件中使用 Windows raw_input

javascript - 有什么比 setTimeout 和 requestAnimationFrame 更快的吗?

javascript - 使 javascript 警告/确认对话框更加可见(尤其是在 Google Chrome 浏览器中)

html - 如何获取 Chrome 扩展程序中的根文件夹?

javascript - AsyncTestCompleter Browserify Angular2 HTTP 模拟测试

javascript - Instafeed.js 和 jQuery colorbox