Keyboard media keys in Windows - is it possible to override which app responds to key presses?
Solution 1
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.
Solution 2
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.
Solution 3
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.
Related videos on Youtube
Jon
Updated on September 18, 2022Comments
-
Jon over 1 year
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?
-
Admin about 7 yearsit's possible this is in the keyboard configuration rather than windows - can you share the keyboard brand and model number?
-
Admin about 7 years@LevenTech It's just a generic 'AOpen' keyboard, no special software or drivers.
-
Admin almost 6 yearsI have the same problem -- when I have ITunes open on Windows 10, it "claims" the media keys (play / pause etc.), but I want to control Windows Media Player. I wish there was a way to control which app gets the global keypress. I can't see any way in ITunes to ask it to stop listening.
-
Admin over 3 yearswith Firefox 81.0b5 the media button controlled both some random video in the browser and the Spotify app at the same time.. It was very annoying and this was the top search result when looking for a solution => FYI for anyone affected: there is a setting in about:config
media.hardwaremediakeys.enabled
which can be switched to false to disable the feature until Windows makes a better job with configuration of this feature
-
-
Jon about 7 yearsThis is mostly unrelated from the question at hand - plus I said "ideally change it without disabling the extension or closing Chrome every time I want to use my media keys with Spotify?" The issue at hand is how does Windows decide who gets to see the keypresses.
-
LevenTech about 7 yearsI think the global/chrome-only toggle in Chrome makes it clear that Windows allows apps to declare their own key capturing. I don't think I suggested closing Chrome or deleting the extension - do you mean that you need a solution that allows you to keep the Focus on Chrome?
-
bertieb almost 6 yearsThank you for you contribution! As it stands this reads more like a comment than an answer- it would be preferable to include the information from that answer in your answer (with attribution). Please edit your answer to include that information :)
-
Nelson Hoover almost 6 yearsHi, I added more detail. Does that work?
-
Rich almost 6 yearsThis is a great idea, but it doesn't quite work for me. ITunes still seems to "steal" the media key press from WMP, even if WMP is the active window. If I have WMP active and press "Media_Play_Pause", then the current song will start playing in ITunes :-(. I am fine with using AHK. I tried the above script but using "Media_Play_Pause" instead of
^L
. Any idea how I can "send" a key but have it seen only by a particular app? -
Rich almost 6 years
ControlSend
does not appear to work for sending theMedia_Play_Pause
key only to WMP and not to ITunes. -
Rich almost 6 yearsThis works for me: gist.github.com/RichardBradley/9ca64bee1793b12a19725e67343c0224 Thanks! I can use
ControlSend
to sendctrl+p
to WMP when iTunes is open, and suppress theMedia_Play_Pause
key. I'll give you the 50pts when I can (looks like tomorrow) -
Nelson Hoover almost 6 yearsGlad to see you got it working in spite of my admittedly vague answer. I added your actual code to the answer to make it easier for others who may run into this (if you don't mind).
-
x d over 4 yearsDo you know of any keyboard shorcut to access functionality?
-
John Stock almost 4 yearsIt might help to let us know where this built in toggle button is!
-
Rob Williams almost 4 years@JohnStock It's the arrow down the right side.
-
Serhii Kheilyk over 3 years@xd, this is shown when you change volume by media keys
-
Debie Downer over 3 years@SerhiiKheilyk I think that's clear; the question is if it is possible to "click" that shown button with a keyboard shortcut. Otherwise you need to do
media key on keyboard
->move cursor and click
->media key on keyboard again
(ormove cursor and click again
). Not very convenient for those who would rather stay on the keyboard. -
MrEduar about 3 yearsNot work for me
-
MrEduar about 3 years@DebieDowner Have you found a solution to this problem?
-
Martijn about 3 yearsFor me this doesn't seem to toggle anything. It just shows what's playing on other applications.
-
Jez almost 3 yearsDoes anyone know if you can bind this toggle button in AHK or something similar?