mpower

Sending key presses to Spotify

3 posts in this topic

#1 ·  Posted (edited)

Hi everyone, I've quickly slapped together a Keyboard short-cut tray script that controls Spotify using Numpad keys but for some reason the Space key (HotKey numpad 5) and the Ctrl + Shift + Down (HotKey numpad divide) combinations are not working. All others are working fine.

The list of Spotify keyboard shortcuts is here: https://support.spotify.com/is/learn-more/faq/#!/article/Keyboard-shortcuts

I have tested them all manually using my keyboard and they all work fine. But when the script is sending the two above keys the app doesnt seem to detect them.

Here's the entire code (it's a pretty simple script):

HotKeySet("{NUMPAD4}", "PreviousSong")
HotKeySet("{NUMPAD6}","NextSong")
HotKeySet("{NUMPADADD}","CurrentSong")
HotKeySet("{NUMPADSUB}","CloseApp")
HotKeySet("{NUMPADDIV}","Mute")
HotKeySet("{NUMPAD8}","VolumeUp")
HotKeySet("{NUMPAD2}","VolumeDown")
HotKeySet("{NUMPAD5}","PlayPause")

While 1
    Sleep(10)
WEnd

Func PlayPause()
   ControlSend(WinGetTitle("[CLASS:SpotifyMainWindow]"), "", "", "{space}")
   ConsoleWrite("Play/Pause"&@CRLF)
EndFunc

Func NextSong()
   ControlSend(WinGetTitle("[CLASS:SpotifyMainWindow]"), "", "", "^{right}")
   ConsoleWrite("Next song"&@CRLF)
EndFunc

Func PreviousSong()
   ControlSend(WinGetTitle("[CLASS:SpotifyMainWindow]"), "", "", "^{left}")
   ConsoleWrite("Previous song"&@CRLF)
EndFunc

Func CurrentSong()
    Local $song = WinGetTitle("[CLASS:SpotifyMainWindow]")
    TrayTip("", $song, 1)
    ConsoleWrite("Current song name: "&$song&@CRLF)
EndFunc

Func Mute()
    ControlSend(WinGetTitle("[CLASS:SpotifyMainWindow]"), "", "", "^+{down}")
    ConsoleWrite("Mute"&@CRLF)
EndFunc

Func VolumeUp()
    ControlSend(WinGetTitle("[CLASS:SpotifyMainWindow]"), "", "", "^{up}")
    ConsoleWrite("VolumeUp"&@CRLF)
EndFunc

Func VolumeDown()
    ControlSend(WinGetTitle("[CLASS:SpotifyMainWindow]"), "", "", "^{down}")
    ConsoleWrite("VolumeDown"&@CRLF)
EndFunc

Func CloseApp()
    Exit
EndFunc

Help would be appreciated :)

Edited by mpower

Share this post


Link to post
Share on other sites



Hello.

It seems that this is a issue in the new versions of Spotify. For some reason, the space key being sent to it doesn't work. 

I also tried with AutoHotKey (which is sometimes better than AutoIT for some things) and it also works with EVERYTHING BUT the space key to play/pause.

It really sucks that Spotify didn't think about creating global hotkeys yet. Or maybe they can't do it because its so diffucult that even they won't override it hahaha!

Another alternative is Toastify, but its so freaking slow... When you press the key, it takes up to 20 seconds sometimes just to pause/play.

 


Just a server analyst that has never been into programming that much. So, small fish here :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hey Guys sorry for the bump, I'd say this is maybe recent enough ;)

I was looking for a way to pause Spotify using my mouse keys while working inside a VMware machine.

I came up with this to do it. You could use hotkeyset or have your mouse launch the exe if it can.

;~ HotKeySet("+^!'", "ToggleSpotify")
;~ While 1
;~ WEnd

ToggleSpotify()

Func ToggleSpotify()
   Local $w = WinGetHandle("")
   WinSetState($w, "", @SW_MINIMIZE)
   WinActivate("[CLASS:SpotifyMainWindow]")
   Local $s = WinGetPos("[CLASS:SpotifyMainWindow]")
   Local $m = MouseGetPos()
   MouseClick("primary", $s[0], $s[1], 1, 1)
   Send("{MEDIA_PLAY_PAUSE}")
   WinActivate($w)
   MouseMove($m[0], $m[1], 1)
EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now