Allowed Keyboard Shortcuts for Chrome Extensions

风格不统一 提交于 2019-12-13 12:16:46

问题


When you creating a Chrome browser extension, you may suggest keyboard shortcuts by implementing the chrome.commands API. Is there a documented list of allowed key combinations? Chrome seems to reject virtually every combination I offer despite the fact that I know they are not used by any of the systems I'm targeting.

I'm aware of the keyboard shortcuts listed here, but shortcuts not appearing on this list still do not work.


回答1:


The documentation is quite precise in that respect. I will quote the documentation, but be aware it's subject to change. This answer is based on documentation as of 2015-02-09

Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Space, Insert, Delete, Arrow keys (Up, Down, Left, Right) and the Media Keys (MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).

Note: All key combinations must include either Ctrl* or Alt. Combinations that involve Ctrl+Alt are not permitted in order to avoid conflicts with the AltGr key. Shift can be used in addition to Alt or Ctrl, but is not required. Modifiers (such as Ctrl) can not be used in combination with the Media Keys. Tab key was removed from list of supported keys in Chrome version 33 and above for accessibility reasons.

  • Also note that on Mac 'Ctrl' is automatically converted to 'Command'. If you want 'Ctrl' instead, please specify 'MacCtrl'.

So, a combination MUST contain Ctrl or Alt but not both, optionally contain Shift and then one of the "supported keys".

Additionally,

Certain Chrome shortcuts (e.g. window management) always take priority over Extension Command shortcuts and can not be overwritten.

This covers commands that Chrome listens to while focused. For system-level commands, it is restricted to Ctrl+Shift +(number)

There are additional rules specifically for Chrome OS, read the same documentation for those.


Also, note that changing suggested keys for an already-installed extension may not trigger their assignment. Try to reinstall the extension instead of reloading it when testing.

Finally, as Whymarrh suggested, you can see the keybindings at chrome://extensions/shortcuts



来源:https://stackoverflow.com/questions/28401138/allowed-keyboard-shortcuts-for-chrome-extensions

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