Global Hotkeys via Media Session
Looks like it is indeed possible to have yet another form of global hotkeys. We can start a media session and pretend we are playing music, at which point the browser will forward any key presses of the media keys on your keyboard (or any other way of pausing, playing, skipping, ... the current song, such as pressing buttons on your headphones) to custom JavaScript code you can execute:
https://developer.mozilla.org/en-US/docs/Web/API/MediaSession
if ('mediaSession' in navigator){
navigator.mediaSession.metadata = new MediaMetadata({
title: "Podcast Episode Title",
artist: "Podcast Host",
album: "Podcast Name",
artwork: [{src: "podcast.jpg"}]
});
navigator.mediaSession.setActionHandler('play', function() {});
navigator.mediaSession.setActionHandler('pause', function() {});
navigator.mediaSession.setActionHandler('seekbackward', function() {});
navigator.mediaSession.setActionHandler('seekforward', function() {});
navigator.mediaSession.setActionHandler('previoustrack', function() {});
navigator.mediaSession.setActionHandler('nexttrack', function() {});
}
Seems like you may need to play some actual audio or so for this to work.
"Yet another way"? What's the first way?
All of them are kind of suboptimal:
- You can assign gamepad buttons. Those work globally.
- Technically it's possible to have global hotkeys via a browser extension, it's not implemented yet though.
- Another possibility is to use the websocket support to send the hotkeys.
This seems promising - would we want some way of customizing what each of these keys maps to in LiveSplit? Right now the mapping in settings is from action --> key, whereas in this case we would want to customize the press of a media key --> action.