Using Media Keys without using a global shortcut?


I want to use media keys in my electron app, but only when I have focus on my application. I’ve tried adding them to a menu but that doesn’t seem to work. Is there a way to do this?

var app = require('app');
var globalShortcut = require('global-shortcut');
var Menu = require('menu');

app.on('ready', function() {
    var menu = Menu.buildFromTemplate([{
        label: 'Controls',
        submenu: [
            {label: 'Play', accelerator: 'MediaPlayPause', click: function() { console.log('this doesn\'t work') } },
            {label: 'Next', accelerator: 'ctrl+t', click: function() { console.log('this works fine')}}


    globalShortcut.register('MediaNextTrack', function() { console.log('this hijacks all the media keys'); });

Something similar to this for Mac would be ideal:


Yeah, I would like to know that too


Looks like you could use some JS detection of window focus

ar window_focus;

$(window).focus(function() {
    window_focus = true;
}).blur(function() {
    window_focus = false;

$(document).one('click', function() {
    setInterval(function() {
        $('body').append('has focus? ' + window_focus + '<br>');
    }, 1000);