6

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.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Tom Wright
  • 11,278
  • 15
  • 74
  • 148

2 Answers2

4

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);
});
Community
  • 1
  • 1
schellmax
  • 5,678
  • 4
  • 37
  • 48
  • Yes, but have you tried the media keys? They are not listed as allowed global commands. – Xan Apr 12 '15 at 17:20
  • Haven't tried, but under 'Usage' the docs say: Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Space, Insert, Delete, Arrow keys (Up, Down, Left, Right) **and the Media Keys (MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).** – schellmax Apr 12 '15 at 18:39
  • And further down, _"the extension developer is limited to specifying only Ctrl+Shift+[0..9] as global shortcut"_. – Xan Apr 12 '15 at 18:40
  • My fault, i'm sorry. Anyway, the OP stated 'Doesn't have to be media keys' so i guess the answer is valid - but you're right, no media keys. – schellmax Apr 12 '15 at 18:42
  • Can you test, considering you have a sample all set up? – Xan Apr 12 '15 at 18:43
  • hey, i just tried 'MediaPlayPause' and it works too! docs are behind here it seems! – schellmax Apr 12 '15 at 18:46
  • Which platform did you test? Can you leave a comment about that on https://code.google.com/p/chromium/issues/detail?id=131612 ? – Xan Apr 12 '15 at 18:51
  • posted on google code: https://code.google.com/p/chromium/issues/detail?id=131612#c63 – schellmax Apr 12 '15 at 18:56
  • Thanks. I guess you can update your answer then. Upvoting in advance. – Xan Apr 12 '15 at 18:57
1

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).

mangini
  • 4,179
  • 2
  • 19
  • 23