Skip to content

Instantly share code, notes, and snippets.

@stares
Forked from anonymous1184/README.md
Created January 21, 2022 14:06
Show Gist options
  • Save stares/a94f180ea75fd1026e98cc3079dbc1b3 to your computer and use it in GitHub Desktop.
Save stares/a94f180ea75fd1026e98cc3079dbc1b3 to your computer and use it in GitHub Desktop.
Spotify Keys (APP)

; About: https://redd.it/orzend
/*
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() ; Or system-wide: Media_Next
2::Spotify.previous() ; Or system-wide: Media_Prev
3::Spotify.repeat()
4::Spotify.seekBackward()
5::Spotify.seekForward()
6::Spotify.shuffle()
7::Spotify.togglePlay() ; Or system-wide: Media_Play_Pause
8::Spotify.volumeDown() ; Or system-wide: Volume_Down
9::Spotify.volumeUp() ; Or system-wide: Volume_Up
; Show Spotify:
0::Spotify.restore()
#Include Spotify.ahk
; Or if using a Lib:
; #Include <Spotify>

class Spotify extends Spotify.Controls
{
static _hWnd := -1
restore()
{
new this._win
WinShow
WinActivate
this._hWnd := -1
}
class Controls
{
__Call(action)
{
shortcut := { ""
. "next" : "^{Right}"
, "previous" : "^{Left}"
, "repeat" : "^r"
, "seekBackward": "+{Left}"
, "seekForward" : "+{Right}"
, "shuffle" : "^s"
, "togglePlay" : "{Space}"
, "volumeDown" : "^{Down}"
, "volumeUp" : "^{Up}" }[action]
if !shortcut
throw Exception("Invalid action: " action, -1)
instance := new this._win(true)
ControlFocus Chrome Legacy Window
ControlSend, Chrome Legacy Window, % shortcut
if action in next,previous,togglePlay
PostMessage 0xC028, 0x0C, 0xA0000,, % "ahk_id" DllCall("User32\FindWindow", "Str","NativeHWNDHost", "Ptr",0)
}
}
class _win
{
static _tmm := A_TitleMatchMode
, _dhw := A_DetectHiddenWindows
__New(stash := false)
{
SetTitleMatchMode 2
DetectHiddenWindows On
if !hWnd := WinExist(" - ahk_exe Spotify.exe")
if !hWnd := WinExist("Spotify ahk_exe Spotify.exe")
throw Exception("App not running...", -1)
if (Spotify._hWnd = hWnd)
return this
Spotify._hWnd := hWnd
if !DllCall("User32\IsWindowVisible", "Ptr",hWnd)
{
RunWait Spotify.exe, % A_AppData "\Spotify"
if stash
WinHide
}
}
__Delete()
{
SetTitleMatchMode % this._tmm
DetectHiddenWindows % this._dhw
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment