开发者

Listen to KeyStrokes from all the pages in Google Chrome

开发者 https://www.devze.com 2022-12-14 23:52 出处:网络
What exactly I am trying to do is add on m开发者_如何学Pythonore shortcuts to Google Chrome browser. As of now I am using window.addEventListener(\'keyup\', keyCheck, false);.

What exactly I am trying to do is add on m开发者_如何学Pythonore shortcuts to Google Chrome browser. As of now I am using window.addEventListener('keyup', keyCheck, false);. I post a message then to the background page to carry out the relevant task.

I wonder if there is a way to achieve this when the current tab doesn't show any proper page (like newtab page, or extensions page, downloads page etc..)?


You currently cannot inject any scripts in chrome://* pages or about:* pages that includes newtab, extensions, version, etc.

An example on how you can do keyboard shortcuts would be something like this:

[source]

if (window == top) {
  window.addEventListener("keyup", keyListener, false);
}

// Keyboard keyup listener callback.
function keyListener(e) {
  // Must press ctrl key to validate.
  if (e.ctrlKey && e.keyCode && !e.metaKey) {
    chrome.extension.sendRequest({
      code: e.keyCode,
      alt: e.altKey,
      shift: e.shiftKey
    });
  }
}

You can override those pages, but that would be an ugly fix.

0

精彩评论

暂无评论...
验证码 换一张
取 消