Usage and information: https://redd.it/orzend
Last active
January 3, 2025 18:24
-
-
Save anonymous1184/64fe98f2d25c8faaeea11ebae7bf1014 to your computer and use it in GitHub Desktop.
Spotify Keys (APP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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 |
@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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
workin great btw.
the other one i used that used api calls stopped working for me but your um... unique method. is working still :)