How to write a Google Chrome extension that disables a default keyboard-shortcut?

为君一笑 提交于 2020-01-07 04:01:31

问题


I need a Google Chrome extension that simply disables the built in alte shortcut and pass it to the HTML accesskey as ordinary. (yes, that all - no configuration/graphics)

It's for an in-house web-application and I don't want to use existing extensions.

I've browsed the extension documentation but would be thankful for a jump start in this matter.


回答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.

Related Question: Keyboard Shortcuts in Google Chrome / Chromium Extensions




回答2:


For reference, (modified from http://www.catswhocode.com/blog/using-keyboard-shortcuts-in-javascript):

var isAlt = false;
$(document).keyup(function (e) {
  if(e.which == 18) isAlt=false;
}).keydown(function (e) {
  if(e.which == 18) isAlt=true;
  if(e.which == 69 && isAlt == true) {
    alert('Keyboard shortcuts + JQuery are even more cool!');
    return false;
  }
});    


来源:https://stackoverflow.com/questions/18249790/how-to-write-a-google-chrome-extension-that-disables-a-default-keyboard-shortcut

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