Keyboard Shortcuts in Google Chrome / Chromium Extensions

旧城冷巷雨未停 提交于 2019-12-18 11:34:27

问题


I've created a basic extension for Google Chrome to change the behavior of which tab is selected when you close a tab so that the selected tab is the last one you had selected instead of just the one before the tab you closed.

I want to add keyboard shortcuts, and I've found a way to do that using jquery and jquery hotkeys, but the problem I'm finding is that the keyboard shortcuts only work once a page is loaded. So for example, if you open a new tab without going anywhere, the shortcut keys don't work because the javascript only loads when a page is on the screen. Same problem if you have the extensions page open in a tab.

Does anyone know of a better way to do keyboard shortcuts in Chrome extensions? I've been looking through the extensions documentation, but I haven't found anything that looks promising.


回答1:


Unfortunately there's no way to hook into global hotkeys. The best you can do is add a window event keypress listener.

Source: a Chromium developer post on the chromium-extensions group.




回答2:


Just as an update it's actually being developed now:

http://developer.chrome.com/trunk/apps/commands.html




回答3:


Keyboard shortcuts are implemented with chrome.commands in Chrome 25 and above: developer.chrome.com/apps/commands.html.



来源:https://stackoverflow.com/questions/2115083/keyboard-shortcuts-in-google-chrome-chromium-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!