Created
May 3, 2015 16:38
-
-
Save senevoldsen/b233ce4f77e835eb7529 to your computer and use it in GitHub Desktop.
Global hotkeys for YouTube media player in Firefox.
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
Local Const $kTitleForYoutubeTab = "[REGEXPTITLE:(?i)(.*YouTube - Mozilla Firefox.*)]" | |
Local Const $kTitleForFirefox = "[REGEXPTITLE:(?i)(.*Mozilla Firefox.*)]" | |
Local Const $kKeyPlayPause = "k" | |
Local Const $kKeyNext = "+n" | |
Local Const $kKeyPrev = "+p" | |
HotKeySet("{MEDIA_PLAY_PAUSE}", "PlayPause") | |
HotKeySet("{MEDIA_NEXT}", "NextTrack") | |
HotKeySet("{MEDIA_PREV}", "PrevTrack") | |
Func FindTab() | |
Local $ffHandle = WinGetHandle($kTitleForFirefox) | |
If $ffHandle = 0 Then | |
Return 0 | |
EndIf | |
; Bound time. Frequently this loop will never actually loop. | |
For $i = 0 to 40 | |
Local $ytHandle = WinGetHandle($kTitleForYoutubeTab) | |
If $ytHandle <> 0 Then | |
Return $ytHandle | |
EndIf | |
; Skip to next tab | |
ControlFocus($ffHandle, "", "") | |
ControlSend($ffHandle, "", "", "^{TAB}") | |
Sleep(5) | |
Next | |
Return 0 | |
EndFunc | |
Func PlayPause() | |
Local $ytHandle = FindTab() | |
If $ytHandle <> 0 Then | |
ControlSend($ytHandle, "", "", $kKeyPlayPause) | |
EndIf | |
EndFunc | |
Func NextTrack() | |
Local $ytHandle = FindTab() | |
If $ytHandle <> 0 Then | |
ControlSend($ytHandle, "", "", $kKeyNext) | |
EndIf | |
EndFunc | |
Func PrevTrack() | |
Local $ytHandle = FindTab() | |
If $ytHandle <> 0 Then | |
ControlSend($ytHandle, "", "", $kKeyPrev) | |
EndIf | |
EndFunc | |
While 1 | |
Sleep(25) | |
WEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment