Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Spotify Global Hotkeys


  • Please log in to reply
23 replies to this topic
Sansana
  • Members
  • 1 posts
  • Last active: Jan 19 2009 02:11 AM
  • Joined: 04 Jan 2009
Hello,
I know there's a topic like this already, but in Ask for help section, and I believe this is a more fitting place for this. This tiny script is based on zzzTAG's script from this topic <!-- m -->http://www.autohotke...topic38617.html<!-- m --> .

It's basically a global hotkeys script which includes a little clipboard extra feature. It covers all playback hotkeys such as: previous, next, play/pause, volume up, volume down and mute. The little extra feature I've mentioned above allows you to copy current song's name (Artist - Title) to clipboard - I think it's a very useful thing :)

Here's the code:
SetTitleMatchMode 2 

; "CTRL + LEFT"  for previous 
^Left:: 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Left}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 


; "CTRL + RIGHT"  for next 
^Right:: 
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
} 

; "CTRL + UP"  for pause
^UP::
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, {space}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
} 

; "CTRL + DOWN"  for info 
^Down:: 
{ 
DetectHiddenWindows, On 
SetTitleMatchMode 2 
WinGetTitle, now_playing, ahk_class SpotifyMainWindow 
StringTrimLeft, playing, now_playing, 10 
DetectHiddenWindows, Off 
clipboard = %playing%`r`n
return 
} 

; "CTRL + PAGE UP"  for volume up
^PgUP::
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Up}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
} 

; "CTRL + PAGE DOWN"  for volume down
^PgDn::
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{Down}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
} 

; "CTRL + END"  for mute
^End::
{ 
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^+{Down}, ahk_class SpotifyMainWindow 
DetectHiddenWindows, Off 
return 
}

Here's the program : <!-- m -->http://rapidshare.co... ... y.exe.html<!-- m -->

The keys goes like this:

Previous - Ctrl + Left
Next - Ctrl + Right
Play/Pause - Ctrl + Up
Copy song name to clipboard - Ctrl + Down
Volume up - Ctrl + Page Up
Volume down - Control + Page Down
Mute - Control + End

Enjoy!

michaelJ
  • Guests
  • Last active:
  • Joined: --
Very convenient. Thank's alot.

Elias
  • Guests
  • Last active:
  • Joined: --
Link is dead? :(

ibr
  • Members
  • 5 posts
  • Last active: Aug 01 2010 01:55 PM
  • Joined: 12 Aug 2009
Great script, I was looking at a VB.NET class that does the same, but it cannot change song (next/previous) without focusing the window. AutoHotKey never stop to impress me :)

Antonimo
  • Members
  • 55 posts
  • Last active: Feb 13 2019 11:59 AM
  • Joined: 28 Apr 2006
Ha Ha!

I did a quick search in Google for spotify global hotkey and the top link came here.

I should have come to Autohotkey in the first place.

The link above may not work, but creating the AHK script with the code gives more control over which hotkeys to assign.

Thanks Sansana - Very useful.

tuna
  • Members
  • 158 posts
  • Last active: Dec 28 2012 04:50 PM
  • Joined: 03 Oct 2007
Had a similar idea a while back trying to skip Spotify ads. It allows you to easily add as many hotkeys as you want just by adding variables hotkeyN and hotkeyNSend at the top of the script, where N is the next highest variable number. If you're interested:

make a script to play next song a split second before the previous one finishes? ads would never start?

Sound idea, so done a quick script - can't get the ClassNN of Spotify controls so detecting the end of a track is left to the user via hotkeys.
Set as many hotkeys as you like to control Spotify in the background.
#Persistent
DetectHiddenWindows, On
SetBatchLines, -1
SetWinDelay, -1

;Hotkeys must be named sequentially and consecutively like so:
hotkey1				  = ^+d				; previous
hotkey1Send			 = {UP}{ENTER}
hotkey2				  = ^+c				; next
hotkey2Send			 = {DOWN}{ENTER}
hotkey3				  = ^+x				; pause
hotkey3Send			 = {SPACE}
hotkey4				 = ^+r				 ; repeat
hotkey4Send			 = {ENTER}
winTitle				 = ahk_class SpotifyMainWindow

Loop {
	If !hotkey%A_Index%
		Break
	Hotkey, % hotkey%A_Index%, winSend
	hashCurr := "hash" . hashFunction(hotkey%A_Index%)
	%hashCurr% := hotkey%A_Index%Send
}
Return

winSend:
hotkeyHash := "hash" . hashFunction(A_ThisHotkey)
ControlSend, , % %hotkeyHash%, %winTitle%
Return

hashFunction(str) {
	SetFormat, IntegerFast, H
	str := hashFunctionTransform(str)
	SetFormat, IntegerFast, D
	Return str
}

hashFunctionTransform(str) {
	Return Substr((Asc(Str) + 0), 3) . (StrLen(Str) > 1 ? hashFunction(SubStr(Str, 2)) : "")
}

Full post at http://www.autohotke...er=asc&start=22

On a related note, since then I've also tried to get rid of audio ads completely, but also contains hotkeys to control Spotify still:

Features
> Skips Spotify's audio ads without any user intervention
> Spotify playback controls available through unobtrusive (and draggable) mini UI
> Control master volume via mouse
> Detects Spotify window closure, opening, minimisation etc and handles in all those situations
> Automatic software updates
> Portable - put it on a flash drive and run it on any computer


Posted Image


Usage
Run Stopify, and just play songs in Spotify as normal - easy.
Double click tray icon to toggle show/hide.

Hotkeys: Ctrl+Shift+...
...Mouse Scroll (MButton) Click/Scroll Down/Scroll Up or ...Q/W/E: (master) mute/volume down/volume up
...Z/X/C: previous/toggle play/next song
...A/S: shuffle/repeat
...D/F: Spotify volume down/volume up

For more see http://www.autohotke...p=411058#411058


Thanks

robertpateii
  • Members
  • 1 posts
  • Last active: Aug 12 2011 12:35 AM
  • Joined: 12 Aug 2011
i registered so i could thank the OP, Sansana, for this. It's just what I wanted, and the code posted works great once compiled. I have a few autohotkey scripts that I've tweaked, but I haven't had to write one from scratch yet thanks to the rocking community.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
Guest posting is allowed, but too late now :p

AttckDog
  • Guests
  • Last active:
  • Joined: --
Thanks Man Love it simple !

  • Guests
  • Last active:
  • Joined: --
deadly ;)

CLS55
  • Guests
  • Last active:
  • Joined: --
Sorry for being an idiot but how do I use the code?

...I tried pasting it, as it was, into the AHK programme's script but that didn't seem to do it

CLS55
  • Guests
  • Last active:
  • Joined: --

Sorry for being an idiot but how do I use the code?

...I tried pasting it, as it was, into the AHK programme's script but that didn't seem to do it


...Turns out I'd done it properly and spotify was just frozen

GUEST
  • Guests
  • Last active:
  • Joined: --
THANK YOU!

RedWingB
  • Members
  • 1 posts
  • Last active: Dec 23 2012 02:18 PM
  • Joined: 23 Dec 2012

Registered just to say thanks, this is awesome and saves me plenty of time :).



khromov
  • Members
  • 1 posts
  • Last active: Mar 26 2013 03:25 PM
  • Joined: 26 Mar 2013

Here's a hotkey for switching to a random song in your playlist:

; "CTRL + ALT + D" for random song in playlist
^!D::
{
DetectHiddenWindows, On 
ControlSend, ahk_parent, ^{s}, ahk_class SpotifyMainWindow
Sleep, 100
ControlSend, ahk_parent, ^{Right}, ahk_class SpotifyMainWindow
Sleep, 250
ControlSend, ahk_parent, ^{s}, ahk_class SpotifyMainWindow
DetectHiddenWindows, Off 
return
}