Listen to KeyStrokes from all pages in Google Chrome.

What I'm trying to do is add extra shortcuts to the Google Chrome browser. Right now I'm using window.addEventListener ('keyup', keyCheck, false); Then I send a message to the help page to complete the corresponding task.

I wonder if there is a way to achieve this when the current tab does not show any proper page (e.g. newtab page, extensions page, download page, etc.).

+4
source share
1 answer

Currently, you cannot enter any scripts on chrome: // * or about: * pages, which include newtab, extensions, version, etc.

An example of how you can make 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 these pages, but it will be an ugly fix.

+4
source

All Articles