
Control YouTube Playback in Chrome with AutoHotkey
Drop below script into your AHK file and reload it.
#Persistent
#NoEnv
#SingleInstance, Force
DetectHiddenWindows, On
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 2
controlID := 0
return
#IfWinNotActive, ahk_exe chrome.exe
; Play/pause
+!p::
ControlGet, controlID, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
ControlFocus,,ahk_id %controlID%
IfWinExist, YouTube
{
ControlSend, Chrome_RenderWidgetHostHWND1, k , Google Chrome
return
}
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
}
ControlSend, , k , Google Chrome
return
; Next video in playlist
+!n::
ControlGet, controlID, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
ControlFocus,,ahk_id %controlID%
IfWinExist, YouTube
{
ControlSend, Chrome_RenderWidgetHostHWND1, +n , Google Chrome
return
}
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
}
ControlSend, , +n , Google Chrome
return
; Previous video in playlist
+!b::
ControlGet, controlID, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
ControlFocus,,ahk_id %controlID%
IfWinExist, YouTube
{
ControlSend, Chrome_RenderWidgetHostHWND1, +p , Google Chrome
return
}
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
}
ControlSend, , +p , Google Chrome
return
; Seek back
+!left::
ControlGet, controlID, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
ControlFocus,,ahk_id %controlID%
IfWinExist, YouTube
{
ControlSend, Chrome_RenderWidgetHostHWND1, j , Google Chrome
return
}
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
}
ControlSend, , j , Google Chrome
return
; Seek forward
+!right::
ControlGet, controlID, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
ControlFocus,,ahk_id %controlID%
IfWinExist, YouTube
{
ControlSend, Chrome_RenderWidgetHostHWND1, l , Google Chrome
return
}
Loop {
IfWinExist, YouTube
break
ControlSend, , ^{PgUp} , Google Chrome
sleep 150
}
ControlSend, , +l , Google Chrome
return
#IfWinNotActive
Five keyboard shortcuts are available here: play/pause, next video in playlist, and previous video in playlist, seek back, and seek forward. If you are playing a single video, the next video shortcut would simply start playing the next suggested video. I’ve commented each shortcut above. You can customize it as per your liking, and also remove a particular shortcut if you don’t plan on using it. To add a new shortcut, you can refer this page for the list of shortcuts supported by YouTube.
There are a few points to make note of while using this script due to restrictions implemented in Chrome:
1. If possible, have YouTube as the first tab. Not necessary, but I have seen this gives the fastest response.
2. Have all the tabs in a single Chrome window.
