QUESTION :
Right now I have both Chrome (With ‘Streamkeys’), and Spotify open – and when Chrome isn’t running, Spotify responds to media keys (Pause, skip track, etc.). However when Chrome is open and Streamkeys is running, Streamkeys captures all media key keystrokes. Is there a way to determine which program Windows is sending the media key keypresses to, and ideally change it without disabling the extension or closing Chrome every time I want to use my media keys with Spotify?
ANSWER :
If you’re up to putting some work into it, you might try AutoHotkey, which allows you to script and automate lots of things on your PC.
I’d start with something like the accepted answer in this Stack Overflow post which solves a similar problem of intercepting a key press globally and sending it to a specific window.
In their example (shown below), they are capturing Ctrl+L and sending it to Firefox. In your case, add a copy of the snippet into your script for each key or key combo you wish to capture and modify the MozillaUIWindowClass to whatever app you wish to receive the keystrokes.
They also have a utility called Window Spy for getting any needed information about the destination window, such as name or handle.
$^l::
IfWinExist ahk_class MozillaUIWindowClass
{
WinActivate
Send ^l
}
Or, as Rich ultimately ended up doing, you may need to send commands to the window specifically instead of just giving it focus and sending them globally.
His working solution looks like this:
#IfWinExist ahk_class iTunes
Media_Play_Pause::ControlSend, , ^p, Windows Media Player
#IfWinExist ahk_class iTunes
Media_Next::ControlSend, , ^f, Windows Media Player
#IfWinExist ahk_class iTunes
Media_Prev::ControlSend, , ^b, Windows Media Player
For more help with AutoHotkey scripting, try their documentation page.
In newer version of Windows 10 (version 1903, at least on my PC) there’s a built-in toggle button to let you select which app responds to media keys.
There’s a Keyboard Shortcuts link at the bottom of the Chrome Extensions list . You can get to the list from the Settings menu, by selecting More Tools, then Extensions.
Those settings list all the keyboard shortcuts, grouped by the Extension that uses them. Every shortcut has an option for whether the keyboard shortcut works “Globally” or just “In Chrome”. If that doesn’t work for some reason, you can also delete the keyboard shortcut from Chrome entirely.
Disclamer! This is not my respons, it’s Matt_H’s. I found it on the spotify forum, and thought that it might help you. Here’s the link to the original discussion: https://community.spotify.com/t5/Desktop-Windows/Keyboard-media-launch-button/td-p/1736288
I’ve just been faced with this same problem and managed to solve it by modifying the registry. There’s a standard disclaimer with editing the registry – be careful, be precise, if you break it you get to keep both pieces.
The behaviour of the keys are defined here:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerAppKey16
You can create a string key + value here of “ShellExecute” and the path to your spotify. This is what I’d done with Win7.
However, as an optimisation, Spotify registers “spotify://” as scheme to be handled by Spotify, so a string key + value of “Association” and “spotify” works.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerAppKey16]
“Association”=”spotify”