It might be better to add a Javascript script using Scriptish or Greasemonkey which can listen for u/d keys and interface with the HTML5 player to change volume.
Otherwise, AHK is not very good at interacting with Chrome.
And even SoundSet seems to be kind of limited, as it only controls Master volume.
An approach you *might* be able to do is lower the volume of Chrome through something like this. (Hehe, this was really fun to figure out. Hope this can be helpful to someone.)
The code below uses hotkeys Alt+u and Alt+d. You need to make sure that Google Chrome is running with YouTube as the active tab.
SetTitleMatchMode, 2 ; this line must be in the auto-execute section
#IfWinExist, YouTube - Google Chrome
!u::
SetFormat, FloatFast, 0 ; This is necessary to not get a number like 321.0000000 when we do the division near the end; instead we get 321
Run, sndvol.exe,,Minimize ; sndvol.exe is the Volume Mixer program. Minimize makes it only appear in the taskbar and not interfere with workflow
WinWait, ahk_exe SndVol.exe
WinGet, listVar, ControlList, ahk_exe SndVol.exe
Loop, parse, listVar, `n, `r
{
ControlGetText, text, %A_LoopField% ; each item in the list is checked for its text
If text contains YouTube - Google Chrome
{
controlOfInterest:=A_LoopField ; this will store a value of Static_ where _ is some number.
Break
}
}
StringTrimLeft, staticNumber, controlOfInterest, 6
staticNumber++ ; add 1 to this number
suffix:=staticNumber/3 ; find out how many times this can be divided by 3, stored in variable suffix
suffix+=320 ; add 320 to suffix
ControlSend, msctls_trackbar%suffix%, {up 10}, ahk_exe SndVol.exe
WinClose, ahk_exe SndVol.exe
return
!d::
SetFormat, FloatFast, 0 ; This is necessary to not get a number like 321.0000000 when we do the division near the end; instead we get 321
Run, sndvol.exe,,Minimize ; sndvol.exe is the Volume Mixer program. Minimize makes it only appear in the taskbar and not interfere with workflow
WinWait, ahk_exe SndVol.exe
WinGet, listVar, ControlList, ahk_exe SndVol.exe
Loop, parse, listVar, `n, `r
{
ControlGetText, text, %A_LoopField% ; each item in the list is checked for its text
If text contains YouTube - Google Chrome
{
controlOfInterest:=A_LoopField ; this will store a value of Static_ where _ is some number.
Break
}
}
StringTrimLeft, staticNumber, controlOfInterest, 6
staticNumber++ ; add 1 to this number
suffix:=staticNumber/3 ; find out how many times this can be divided by 3, stored in variable suffix
suffix+=320 ; add 320 to suffix
ControlSend, msctls_trackbar%suffix%, {down 10}, ahk_exe SndVol.exe
WinClose, ahk_exe SndVol.exe
return
#If
As a note, this is only tested on my Windows 8.1 system. It *might* not work if you have more than 9 applications open in the Volume Manager (I only had 7), but I think it will work.
This will launch a minimized instance of the Volume Mixer. In a fraction of a second it should search out the text of a control, which will happen to be the Window Title of existing windows that can play sounds. There is an associated Slider with that Title, and this code manages to find it. There may be a better approach (if I could go through the parent and other children of a control, in other words the siblings of a control, this may have been easier.)
This code can be polished a bit, but I procrastinated on my studying enough. So I'll leave it as is.