在 Javascript 中使用特殊键进行按键操作

发布于 2024-09-04 05:11:36 字数 721 浏览 5 评论 0原文

我想知道是否可以使用 macbook pro 的特殊按键来控制音乐并在 JavaScript 中绑定它们? 示例键:播放/暂停、下一首、后退。

如果有帮助的话,我正在尝试这样做来修改greasemonkey脚本。

这是当前代码

HotKeys.bindings['/'] = HotKeys.activateSearch;
HotKeys.bindings['p'] = HotKeys.playPrev;
HotKeys.bindings['n'] = HotKeys.playNext;
HotKeys.bindings['k'] = HotKeys.selectPrev;
HotKeys.bindings['j'] = HotKeys.selectNext;
HotKeys.bindings['o'] = HotKeys.playSelected;
HotKeys.bindings['v'] = HotKeys.openBlog;
HotKeys.bindings['s'] = HotKeys.toggleFavorite; 

HotKeys.keyBindings[27] /*ESC*/ = HotKeys.deactivateSearch;

脚本源:http://userscripts.org/scripts/review/23612

I was wondering if it was possible to use special keys that the macbook pro has for music control and bind them in javascript?
Example keys: PLay/pause,next, back.

I am trying to do this to modify a greasemonkey script if that helps.

Here is the current code

HotKeys.bindings['/'] = HotKeys.activateSearch;
HotKeys.bindings['p'] = HotKeys.playPrev;
HotKeys.bindings['n'] = HotKeys.playNext;
HotKeys.bindings['k'] = HotKeys.selectPrev;
HotKeys.bindings['j'] = HotKeys.selectNext;
HotKeys.bindings['o'] = HotKeys.playSelected;
HotKeys.bindings['v'] = HotKeys.openBlog;
HotKeys.bindings['s'] = HotKeys.toggleFavorite; 

HotKeys.keyBindings[27] /*ESC*/ = HotKeys.deactivateSearch;

Script source: http://userscripts.org/scripts/review/23612

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

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

发布评论

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

评论(1

扶醉桌前 2024-09-11 05:11:36

只需将按键事件侦听器应用于文档并将事件记录到控制台,以便您可以查看它是否注册。与此类似: http://unixpapa.com/js/testkey.html

Just apply a keypress event listener to the document and log the event to the console so you can see if it registers. Similar to this: http://unixpapa.com/js/testkey.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文