Can Chrome "packaged apps" respond to global keyboard commands?

408 Views Asked by At

I've recently switched from Spotify to Google Music, but miss having a desktop client that responds to keyboard commands. In particular, my laptop has media keys and my fingers keep going to them out of muscle memory.

Media keys found on google images

To remedy this (and other irritations), I've turned Google Play into a packaged app: "Package All Areas"

Unfortunately, I can't seem to find any documentation on getting packaged apps to respond to keyboard shortcuts. Is this possible? Doesn't have to be media keys (if they're tricky), but I'd prefer it if they triggered from anywhere in the OS.

2

There are 2 best solutions below

9
On BEST ANSWER

since chrome 25, there is chrome.commands, and since chrome 35 commands can have global scope (see headline 'Scope').

EDIT: i posted before that the commands api is only available to extensions (and not to 'packaged apps'), because only extensions are explicitly mentioned in the docs - just tried it on a packaged app though, and BOOM - it works :)

EDIT II: although the docs state that "the extension developer is limited to specifying only Ctrl+Shift+[0..9] as global shortcut", i successfully tried using 'MediaPlayPause' as a global shortcut on OSX (thanks to user Xan for pointing me there)

manifest.json:

  "app": {
    "background": {
      "scripts": ["main.js"]
    }
  },
  "commands": {
    "toggle-feature-foo": {
      "suggested_key": {
        "default": "Ctrl+Shift+5"
      },
      "description": "Toggle feature foo",
      "global": true
    }
  }

main.js:

chrome.commands.onCommand.addListener(function(command) {
    console.log('command:',command);
});
0
On

Currently this is not possible in the platform. There is a work in progress, tracked by this bug, to support Media keys.

If you absolutely want to do it now and don't care about complex user requirements, Boris Smus had a good take on this, using a native key interceptor that sends the intercepted command through a websocket to the app (extension in his post, but easily adaptable to an app).