Last active
October 24, 2023 13:03
-
-
Save jcsteh/75fd31cc3efc0016fc86f98f5ba02ca1 to your computer and use it in GitHub Desktop.
AutoHotkey script to make the play/pause button on headsets skip to next/previous track when double/triple pressed
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
; Play/Pause Multi Function | |
; Copyright 2022 James Teh | |
; License: GNU General Public License | |
#SingleInstance Force | |
; Ensure we don't intercept our own sending of play/pause. | |
#If (!sendingPlayPause) | |
Media_Play_Pause:: | |
{ | |
presses += 1 | |
; Don't handle a previous press until we know whether this is a hold. | |
SetTimer, handlePress, Delete | |
; Wait to see if the key is being held. | |
longHoldPresses := 0 | |
SetTimer, handleHold, -500 | |
Return | |
} | |
; GetKeyState doesn't seem to work for Media_Play_Pause, but thankfully this | |
; does. | |
Media_Play_Pause up:: | |
{ | |
SetTimer, handleHold, Delete | |
if (presses = 0) { | |
; This was a hold, not a press. | |
Return | |
} | |
; After each press, delay to give the user time for additional presses. | |
SetTimer, handlePress, -250 | |
Return | |
} | |
#If | |
handlePress: | |
{ | |
if (presses = 1) { | |
sendingPlayPause := true | |
Send {Media_Play_Pause} | |
sendingPlayPause := false | |
} else if (presses = 2) { | |
Send {Media_Next} | |
} else if (presses = 3) { | |
Send {Media_Prev} | |
} | |
presses := 0 | |
Return | |
} | |
handleHold: | |
{ | |
; For fast forward and rewind, we repeat the presses if the | |
; button continues to be held. This is the purpose of longHoldPresses. | |
if (presses = 1) { | |
; Handle single long press | |
} else if (presses = 2 or longHoldPresses = 2) { | |
; Fast forward. Map to shift+nextTrack. | |
Send +{Media_Next} | |
} else if (presses = 3 or longHoldPresses = 3) { | |
; Rewind. Map to shift+previousTrack. | |
Send +{Media_Prev} | |
} | |
if (presses > 0) { | |
longHoldPresses := presses | |
presses := 0 | |
; Handle continued holding of the button. | |
SetTimer, handleHold, 100 | |
} | |
Return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment