I found this AHK v2 script on Github so I can use global hotkeys control Spotify media functions. My use case is that the top row of my USB numpad is tied to F13-15 keys on a 2nd layer and I want to use those to control media only for Spotify. I also want to be able to use it while Spotify is minimized in the taskbar.
Code: Select all
DetectHiddenWindows True
;; Get the handle
getSpotifyHwnd() {
spotifyHwnd := WinGetID("ahk_exe Spotify.exe")
Return spotifyHwnd
}
; Send a key, generic
spotifyKey(key) {
spotifyHwnd := getSpotifyHwnd()
; Chromium ignores keys when it isn't focused.
; Focus the document window without bringing the app to the foreground.
ControlFocus "Chrome_RenderWidgetHostHWND1", "ahk_id " . spotifyHwnd
ControlSend key, , "ahk_id " . spotifyHwnd
Return
}
; Play/Pause
F14::{
spotifyKey("{Space}")
Return
}
Code: Select all
Error: Target control not found.
Specifically: Chrome_RenderWidgetHostHWND1
016: {
017: spotifyHwnd := getSpotifyHwnd()
▶ 020: ControlFocus("Chrome_RenderWidgetHostHWND1", "ahk_id " . spotifyHwnd)
021: ControlSend(key, , "ahk_id " . spotifyHwnd)
022: Return