So I tried many things. My most recent attempt was identifying the window ID and send it via ahk_id, but nothing happens. Sending keystrokes while the window is active is no problem, but I want to be able to do this while playing games, hence the background approach.
Code: Select all
Spotify_HotkeySend(hotkeyString) {
if WinActive("ahk_exe Spotify.exe") {
Send, %hotkeyString%
} else {
id := Get_Spotify_Id()
ControlSend, ahk_parent, %hotkeyString%, ahk_id %id%
}
}
Get_Spotify_Id() {
WinGet, id, list,,, Program Manager
Loop, %id% {
this_id := id%A_Index%
if (Is_Spotify(this_id)) {
return, this_id
}
}
return, -1
}
Is_Spotify(this_id) {
WinGetClass, this_class, ahk_id %this_id%
if (InStr(this_class, "Chrome_WidgetWin_0")) {
WinGetText, this_text, ahk_id %this_id%
if (InStr(this_text, "Chrome Legacy Window")) {
return, true
}
}
return, false
}