在 Javascript 中使用特殊键进行按键操作
我想知道是否可以使用 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;
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将按键事件侦听器应用于文档并将事件记录到控制台,以便您可以查看它是否注册。与此类似: 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