Usage and information: https://redd.it/orzend
-
-
Save anonymous1184/64fe98f2d25c8faaeea11ebae7bf1014 to your computer and use it in GitHub Desktop.
#Requires AutoHotkey v2.0 | |
/* | |
If placing below any hotkeys that had a | |
previous thread change use the default: | |
*/ | |
#MaxThreadsPerHotkey 1 | |
/* | |
Change keys for something meaningful | |
This example is in alphabetical order | |
*/ | |
1::Spotify.Next() | |
2::Spotify.Previous() | |
3::Spotify.Repeat() | |
4::Spotify.SeekBackward() | |
5::Spotify.SeekForward() | |
6::Spotify.Shuffle() | |
7::Spotify.TogglePlay() | |
8::Spotify.VolumeDown() | |
9::Spotify.VolumeUp() | |
; Show Spotify | |
0::Spotify.Restore() | |
; Dependency | |
#Include %A_LineFile%\..\Spotify.ahk |
#Requires AutoHotkey v1.1 | |
/* | |
If placing below any hotkeys that had a | |
previous thread change use the default: | |
*/ | |
#MaxThreadsPerHotkey 1 | |
/* | |
Change keys for something meaningful | |
This example is in alphabetical order | |
*/ | |
1::Spotify.Next() | |
2::Spotify.Previous() | |
3::Spotify.Repeat() | |
4::Spotify.SeekBackward() | |
5::Spotify.SeekForward() | |
6::Spotify.Shuffle() | |
7::Spotify.TogglePlay() | |
8::Spotify.VolumeDown() | |
9::Spotify.VolumeUp() | |
; Show Spotify | |
0::Spotify.Restore() | |
; Dependency | |
#Include %A_LineFile%\..\Spotify1.ahk |
#Requires AutoHotkey v2.0 | |
; Version: 2023.06.18.1 | |
; Usages and information: https://redd.it/orzend | |
class Spotify extends Spotify.Controls { | |
static _hWnd := 0, _OnExit := "" | |
static Restore() { | |
this._Win() | |
WinShow() | |
WinActivate() | |
Spotify._hWnd := 0 | |
if (IsObject(Spotify._OnExit)) { | |
OnExit(Spotify._OnExit, 0) | |
Spotify._OnExit := "" | |
} | |
} | |
static _Win(Stash := false) { | |
static title := "-|Spotify ahk_exe i)Spotify\.exe" | |
DetectHiddenWindows(true) | |
SetTitleMatchMode("RegEx") | |
hWnd := WinExist(title) | |
if (hWnd = 0) { | |
MsgBox("Spotify is not running...", "Error", 0x40010) | |
Exit() | |
} | |
if (Spotify._hWnd = hWnd) { | |
return | |
} | |
Spotify._hWnd := hWnd | |
visible := DllCall("IsWindowVisible", "Ptr", hWnd, "Int") | |
RunWait("Spotify:") | |
WinWait(title) | |
if (Stash && !visible) { | |
WinWaitActive() | |
WinHide() | |
if (!IsObject(Spotify._OnExit)) { | |
Spotify._OnExit := ObjBindMethod(Spotify, "Restore") | |
OnExit(Spotify._OnExit, 1) | |
} | |
} | |
} | |
class Controls { | |
static _shortcuts := Map("Next", "^{Right}", "Previous", "^{Left}", "Repeat", "^r", "SeekBackward", "+{Left}", "SeekForward", "+{Right}", "Shuffle", "^s", "TogglePlay", "{Space}", "VolumeDown", "^{Down}", "VolumeUp", "^{Up}") | |
static __Call(Action, *) { | |
static WM_APPCOMMAND := 793 | |
if (!this._shortcuts.Has(Action)) { | |
throw Error("Invalid action." Action, -1) | |
} | |
shortcut := this._shortcuts[Action] | |
hActive := WinExist("A") | |
this._Win(true) | |
ControlFocus("Chrome Legacy Window") | |
ControlSend(shortcut, "Chrome Legacy Window") | |
if (Action ~= "i)^(Next|Previous|TogglePlay)$") { | |
hWnd := DllCall("FindWindow", "Str", "NativeHWNDHost", "Ptr", 0) | |
try PostMessage(WM_APPCOMMAND, 0x000C, 0xA0000, , hWnd) | |
} | |
WinActivate(hActive) | |
} | |
} | |
} |
#Requires AutoHotkey v1.1 | |
; Version: 2023.06.18.1 | |
; Usages and information: https://redd.it/orzend | |
class Spotify extends Spotify.Controls { | |
static _hWnd := 0, _OnExit := "" | |
Restore() { | |
this._Win() | |
WinShow | |
WinActivate | |
Spotify._hWnd := 0 | |
if (IsObject(Spotify._OnExit)) { | |
OnExit(Spotify._OnExit, 0) | |
Spotify._OnExit := "" | |
} | |
} | |
_Win(Stash := false) { | |
static title := "-|Spotify ahk_exe i)Spotify\.exe" | |
DetectHiddenWindows On | |
SetTitleMatchMode RegEx | |
hWnd := WinExist(title) | |
if (hWnd = 0) { | |
MsgBox 0x40010, Error, Spotify is not running... | |
Exit | |
} | |
if (Spotify._hWnd = hWnd) { | |
return | |
} | |
Spotify._hWnd := hWnd | |
visible := DllCall("IsWindowVisible", "Ptr", hWnd, "Int") | |
RunWait Spotify: | |
WinWait % title | |
if (Stash && !visible) { | |
WinWaitActive | |
WinHide | |
if (!IsObject(Spotify._OnExit)) { | |
Spotify._OnExit := ObjBindMethod(Spotify, "Restore") | |
OnExit(Spotify._OnExit, 1) | |
} | |
} | |
} | |
class Controls { | |
static _shortcuts := { Next: "^{Right}", Previous: "^{Left}", Repeat: "^r", SeekBackward: "+{Left}", SeekForward: "+{Right}", Shuffle: "^s", TogglePlay: "{Space}", VolumeDown: "^{Down}", VolumeUp: "^{Up}" } | |
__Call(Action, _*) { | |
static WM_APPCOMMAND := 793 | |
if (!this._shortcuts.HasKey(Action)) { | |
throw Exception("Invalid action." Action, -1) | |
} | |
shortcut := this._shortcuts[Action] | |
hActive := WinExist("A") | |
this._Win(true) | |
ControlFocus Chrome Legacy Window | |
ControlSend Chrome Legacy Window, % shortcut | |
if (Action ~= "i)^(Next|Previous|TogglePlay)$") { | |
hWnd := DllCall("FindWindow", "Str", "NativeHWNDHost", "Ptr", 0) | |
try PostMessage WM_APPCOMMAND, 0x000C, 0xA0000, , % "ahk_id" hWnd | |
} | |
WinActivate % "ahk_id" hActive | |
} | |
} | |
} |
--- Spotify.ahk | |
+++ Spotify1.ahk | |
@@ -1 +1 @@ | |
-#Requires AutoHotkey v2.0 | |
+#Requires AutoHotkey v1.1 | |
@@ -10 +10 @@ | |
- static Restore() { | |
+ Restore() { | |
@@ -12,2 +12,2 @@ | |
- WinShow() | |
- WinActivate() | |
+ WinShow | |
+ WinActivate | |
@@ -21 +21 @@ | |
- static _Win(Stash := false) { | |
+ _Win(Stash := false) { | |
@@ -23,2 +23,2 @@ | |
- DetectHiddenWindows(true) | |
- SetTitleMatchMode("RegEx") | |
+ DetectHiddenWindows On | |
+ SetTitleMatchMode RegEx | |
@@ -27,2 +27,2 @@ | |
- MsgBox("Spotify is not running...", "Error", 0x40010) | |
- Exit() | |
+ MsgBox 0x40010, Error, Spotify is not running... | |
+ Exit | |
@@ -35,2 +35,2 @@ | |
- RunWait("Spotify:") | |
- WinWait(title) | |
+ RunWait Spotify: | |
+ WinWait % title | |
@@ -38,2 +38,2 @@ | |
- WinWaitActive() | |
- WinHide() | |
+ WinWaitActive | |
+ WinHide | |
@@ -49 +49 @@ | |
- static _shortcuts := Map("Next", "^{Right}", "Previous", "^{Left}", "Repeat", "^r", "SeekBackward", "+{Left}", "SeekForward", "+{Right}", "Shuffle", "^s", "TogglePlay", "{Space}", "VolumeDown", "^{Down}", "VolumeUp", "^{Up}") | |
+ static _shortcuts := { Next: "^{Right}", Previous: "^{Left}", Repeat: "^r", SeekBackward: "+{Left}", SeekForward: "+{Right}", Shuffle: "^s", TogglePlay: "{Space}", VolumeDown: "^{Down}", VolumeUp: "^{Up}" } | |
@@ -51 +51 @@ | |
- static __Call(Action, *) { | |
+ __Call(Action, _*) { | |
@@ -53,2 +53,2 @@ | |
- if (!this._shortcuts.Has(Action)) { | |
- throw Error("Invalid action." Action, -1) | |
+ if (!this._shortcuts.HasKey(Action)) { | |
+ throw Exception("Invalid action." Action, -1) | |
@@ -59,2 +59,2 @@ | |
- ControlFocus("Chrome Legacy Window") | |
- ControlSend(shortcut, "Chrome Legacy Window") | |
+ ControlFocus Chrome Legacy Window | |
+ ControlSend Chrome Legacy Window, % shortcut | |
@@ -63 +63 @@ | |
- try PostMessage(WM_APPCOMMAND, 0x000C, 0xA0000, , hWnd) | |
+ try PostMessage WM_APPCOMMAND, 0x000C, 0xA0000, , % "ahk_id" hWnd | |
@@ -65 +65 @@ | |
- WinActivate(hActive) | |
+ WinActivate % "ahk_id" hActive |
i feel like i'm missing something but surprisingly this is pretty much the only script i've found that'll handle spicefied version. but i've noticed when i first run a hotkey it focuses the window(well activates it in the background) but doesn't do anything until i then minimize and restore spotify.
@NeonLightning: given that I no longer use v1.1, I added the v2.0 version and updated a little the code, adding an extra step to make sure the focused window was not lost (no core functionality was changed).
Check the README.md for version information and the Reddit post for overall details.
ah shame i use it with vmr.ahk to control voicemeeter and that's a 1.0 thanks anyways
@NeonLightning like I've said, check the README.md it contains both versions.
yup finally figured it out. my apologies
workin great btw.
the other one i used that used api calls stopped working for me but your um... unique method. is working still :)
@NeonLightning Thanks for letting me know, I'll check out the API calls and revisit the code as there are improved methods I'd like to implement for that one too.
@anonymous1184
Great solution! Thank you, it is very useful for me