Skip to content

Instantly share code, notes, and snippets.

@derekgates
Last active March 30, 2020 16:29
Show Gist options
  • Save derekgates/6a14d3b307823e374655957d85910e5c to your computer and use it in GitHub Desktop.
Save derekgates/6a14d3b307823e374655957d85910e5c to your computer and use it in GitHub Desktop.
AutoHotkey MediaKey support using built in media commands (or WinAMP if open) which should work with any player in modern Windows versions. I placed this file in %documents% folder so AHK would see it as default script.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; # is WinKey, + is shift
; https://www.autohotkey.com/docs/Tutorial.htm#s2
; https://autohotkey.com/board/topic/70048-ituneswindows-media-playerwinamp-autohotkey-script/
; Detect WinAMP... https://www.autohotkey.com/docs/misc/Winamp.htm
; WinKey + Shift + Right = Next song
#+Right::
If WinExist("ahk_class" . "Winamp v1.x") {
; The above has set the "last found" window for use below.
ControlSend, ahk_parent, b ; Next Track
}
else {
; Otherwise send Mediakeys for any application to respond
Send {Media_Next}
}
; WinKey + Shift + Left = Previous Song
#+Left::
If WinExist("ahk_class" . "Winamp v1.x") {
; The above has set the "last found" window for use below.
ControlSend, ahk_parent, z ; Previous Track
}
else {
; Otherwise send Mediakeys for any application to respond
Send {Media_Prev}
}
; WinKey + Shift + Space = Play/Pause
#+Space::
If WinExist("ahk_class" . "Winamp v1.x") {
; The above has set the "last found" window for use below.
ControlSend, ahk_parent, c ; Pause/Unpause
}
else {
; Otherwise send Mediakeys for any application to respond
Send {Media_Play_Pause}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment