Last active
August 1, 2017 13:05
-
-
Save henkman/5620406 to your computer and use it in GitHub Desktop.
SpotifyHotkey - AutoIt
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
#NoTrayIcon | |
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#AutoIt3Wrapper_Icon=spotify.ico | |
#AutoIt3Wrapper_Outfile=SpotifyHotkey.exe | |
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker | |
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#cs | |
SpotifyHotkey - Adds global Hotkeys to Spotify | |
Just start the SpotifyHotkey.exe, if spotify is not running it will be started. | |
SpotifyHotkey stops if you exit spotify. | |
default hotkeys: | |
play/pause: ALT+E | |
stop: ALT+W | |
next: ALT+D | |
previous: ALT+S | |
In order to change the default create spotify.ini in the same directory as SpotifyHotkey.exe and | |
enter | |
[hotkeys] | |
PlayPause=!e | |
Stop=!w | |
NextTrack=!d | |
PreviousTrack=!s | |
The values behind the equal signs are the hotkeys. | |
See the Remarks section of following page if you wish to modify them: | |
http://www.autoitscript.com/autoit3/docs/functions/Send.htm | |
#ce | |
Const $SPOTIFY_EXE = "spotify.exe" | |
Const $DEFAULT_HOTKEYS[5][2] = [ _ | |
[4, 0], _ | |
["PlayPause", "!e"], _ | |
["Stop", "!w"], _ | |
["NextTrack", "!d"], _ | |
["PreviousTrack", "!s"] _ | |
] | |
Local $processes = ProcessList("SpotifyHotkey.exe") | |
If @error or $processes[0][0] == 2 Then | |
Exit | |
EndIf | |
Local $hotkeys = IniReadSection ("spotify.ini", "hotkeys") | |
If @error Then | |
$hotkeys = $DEFAULT_HOTKEYS | |
EndIf | |
If Not ProcessExists($SPOTIFY_EXE) Then | |
Local $spotify = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\Spotify", "DisplayIcon") | |
If $spotify == "" Then | |
MsgBox(48, "Error", "Spotify is not installed") | |
Exit | |
EndIf | |
If ShellExecute($spotify) == 1 Then | |
MsgBox(48, "Error", "Could not start spotify (" & $spotify & ")") | |
Exit | |
EndIf | |
Sleep(250) | |
Local $tries = 3 | |
While Not ProcessExists($SPOTIFY_EXE) | |
$tries -= 1 | |
If $tries == 0 Then | |
MsgBox(48, "Error", "Could not start spotify (" & $spotify & ")") | |
Exit | |
EndIf | |
Sleep(500) | |
WEnd | |
EndIf | |
For $i = 1 To $hotkeys[0][0] Step 1 | |
If HotKeySet($hotkeys[$i][1], $hotkeys[$i][0]) == 0 Then | |
MsgBox(48, "Error", "Hotkey could not be set") | |
Exit | |
EndIf | |
Next | |
While ProcessExists($SPOTIFY_EXE) | |
Sleep(1000) | |
WEnd | |
Func PlayPause() | |
Send("{MEDIA_PLAY_PAUSE}") | |
EndFunc | |
Func Stop() | |
Send("{MEDIA_STOP}") | |
EndFunc | |
Func NextTrack() | |
Send("{MEDIA_NEXT}") | |
EndFunc | |
Func PreviousTrack() | |
Send("{MEDIA_PREV}") | |
EndFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment