Control Spotify from anywhere in Windows with global keyboard shortcuts, without bringing the app window to the front.
Built with AutoHotkey v2.
- ⏯️ Play / Pause the current track
- ⏭️ Next track
- ⏮️ Previous track
- 🪟 Works even when Spotify is minimized or in the system tray
- 🔒 Single instance: running the script again replaces the previous one
- 🛡️ If Spotify isn't running, the shortcuts simply do nothing (no errors)
| Shortcut | Action |
|---|---|
Ctrl + Alt + Space |
Play / Pause |
Ctrl + Alt + → |
Next track |
Ctrl + Alt + ← |
Previous track |
- Windows 10 or 11
- AutoHotkey v2.0+
- Spotify for Desktop (the desktop app, not the web player)
-
Install AutoHotkey v2 from the official website.
-
Clone or download this repository:
git clone https://github.com/SamuelSchutz13/AHK-SpotifyControl.git
-
Set the path to
Audio.ahkinMain.ahk. Replace this line:#Include "The Destination Path of Audio.ahk"
with the actual path to the file. If both files are in the same folder, just use:
#Include "Audio.ahk"
-
Run
Main.ahkby double-clicking it. An AutoHotkey icon will appear in the system tray.
- Press
Win+R, typeshell:startupand pressEnter. - Create a shortcut to
Main.ahkinside the folder that opens.
That's it: the shortcuts will be active every time you start your PC.
The script finds the Spotify.exe process, gets its window handle (including hidden windows, via DetectHiddenWindows) and sends the Windows WM_APPCOMMAND message directly to it. This is the same command sent by the media keys on a keyboard.
| Action | APPCOMMAND code |
|---|---|
| Next track | 0xB0000 |
| Previous track | 0xC0000 |
| Play / Pause | 0xE0000 |
Because the message goes straight to Spotify, the shortcuts don't interfere with other media players you may have open (browser, YouTube, etc.).
The hotkeys are defined at the top of Main.ahk:
!^Left::SpotifyPlaybackPrevious
!^Space::SpotifyPlaybackPlayPause
!^Right::SpotifyPlaybackNextAutoHotkey modifier symbols:
| Symbol | Key |
|---|---|
^ |
Ctrl |
! |
Alt |
+ |
Shift |
# |
Win |
Example: to use Win + Shift + P for Play/Pause:
#+p::SpotifyPlaybackPlayPauseAHK-SpotifyControl/
├── Main.ahk # Main script: hotkeys and commands sent to Spotify
└── Audio.ahk # Windows Core Audio API library (by thqby)