KeySpotic is a background service to control Spotify using global hotkeys on your system. It allows you to play, pause, skip tracks, and more without opening the Spotify app, using customizable keyboard shortcuts.
The project is cross-platform (Windows, Linux, macOS) and uses:
- BunJS for fast execution and multiplatform builds.
- SQLite to persist Spotify tokens and hotkey configuration.
- node-global-key-listener to capture global keyboard shortcuts.
- Spotify Web API to control playback.
-
Bun ≥ 1.2.x Installation: https://bun.sh
-
Node.js (only if you run external scripts)
-
HTTPS Spotify OAuth requires HTTPS. Place certificates in:
certs/cert.pem certs/key.pemBun will serve the callback endpoint on
https://localhost:<PORT>. -
Spotify Developer Account Required to obtain
clientId,clientSecret, andredirectUri.
- Clone the repository and enter the project:
git clone https://github.com/SammyBytes/KeySpotic
cd keyspotic
bun install- Configure environment variables:
SPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_client_secret
SPOTIFY_REDIRECT_URI=https://localhost:54321/api/v1/spotify/callback
HONO_PORT=54321Note: The
redirectUrimust match the one registered in your Spotify Developer account.
- Generate local certificates if needed:
mkdir certs
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout certs/key.pem -out certs/cert.pemsrc/
├─ index.ts # Main service entry point
├─ listeners/ # Global hotkey listener
├─ modules/
│ ├─ spotify/
│ │ ├─ commands/ # Spotify actions (play/pause/next/prev)
│ │ ├─ config/ # Spotify config and DB
│ │ └─ auth/ # OAuth setup
│ │ └─ routes/ # Hono routes for OAuth callback
├─ hotkeys.json # Configurable hotkeys
certs/ # Local HTTPS certificates
spotify.db # SQLite DB with Spotify tokens
bun run src/index.tsThis will:
- Start the global hotkey listener.
- Check if a Spotify token exists (
spotify.db). - If no token exists, generate a Spotify authorization link.
- Wait for HTTPS callback to save the token.
bun build src/index.ts --outdir dist --target bun
cp -r certs dist/certs
cp hotkeys.json dist/hotkeys.json
cp spotify.db dist/spotify.db
node dist/index.jsThis produces a build ready for end users. Everything runs from the
dist/folder.
Hotkeys are configurable in hotkeys.json:
[
{
"hotkey": "CTRL + ALT + P",
"action": "playPause"
},
{
"hotkey": "CTRL + ALT + RIGHT",
"action": "nextTrack"
},
{
"hotkey": "CTRL + ALT + LEFT",
"action": "previousTrack"
}
]The node-global-key-listener package uses specific nomenclature for key combinations. Here's a breakdown:
LEFT CTRL,RIGHT CTRL: Control keys on the left and right sides of the keyboard.LEFT ALT,RIGHT ALT: Alt keys on the left and right sides.LEFT SHIFT,RIGHT SHIFT: Shift keys on the left and right sides.LEFT META,RIGHT META: Meta keys (e.g., Windows key on Windows, Command key on macOS).
F1toF24: Function keys located at the top of the keyboard.
AtoZ: Alphabetic keys.0to9: Numeric keys.
SPACE: Spacebar.BACKSPACE: Backspace key.ENTER: Enter key.ESCAPE: Escape key.
UP ARROW,DOWN ARROW,LEFT ARROW,RIGHT ARROW: Arrow keys.
NUMPAD 0toNUMPAD 9: Numeric keys on the numpad.NUMPAD PLUS,NUMPAD MINUS,NUMPAD MULTIPLY,NUMPAD DIVIDE: Arithmetic operators on the numpad.
CAPS LOCK,NUM LOCK,SCROLL LOCK: Lock keys.TAB,DELETE,INSERT: Other special keys.
MOUSE LEFT,MOUSE RIGHT,MOUSE MIDDLE: Mouse buttons.
PAGE UP,PAGE DOWN,HOME,END: Scroll keys.
PRINT SCREEN,PAUSE,BREAK: Rarely used keys.
playPause()→ Play / PausenextTrack()→ Skip to next trackpreviousTrack()→ Previous track
| Package | Purpose |
|---|---|
bun:sqlite |
Persist tokens and hotkeys |
node-global-key-listener |
Capture global hotkeys |
spotify-web-api-node |
Interact with Spotify API |
hono |
Handle OAuth callback routes |
- Delete
spotify.dbif you want to reauthorize Spotify. hotkeys.jsonand certificates should be in the same folder asdist/index.jsfor distribution.- HTTPS is required for Spotify OAuth. Self-signed certificates work locally.
- The hotkey listener runs in the background, even if Spotify is minimized.
MIT License © 2025 SammyBytes