Is there a way to listen for keyboard events on a webpage even if the tab and or window is not active (running but not the foreground application). I would assume no due to security concerns but maybe there is some way to archive it with explicit permissions? A service worker?
Basically what I'm trying to do is as following:
window.addEventListener('keydown', event => {
console.log(event.code);
});
As long as the tab is active it works as expected but if the user switches to another application it stops receiving input (also expected), but I am hoping for a way to add a "global" listener.
I know that I'm basically asking for a keylogger but the use-case is a webbased audio player which supports media keys (play/pause, next track, etc) present on some keyboards.