Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Changing Youtube volume shortcut


  • Please log in to reply
3 replies to this topic
roineust
  • Members
  • 1 posts
  • Last active: Jan 08 2015 06:24 PM
  • Joined: 06 Jan 2015

Hello!

 

I want to have different shortcuts for volume up and down (arrows up and down), only when Chrome is open in Youtube while playing a video. for example 'U 'for volume up and 'D' for volume down.

 

Is that possible with the AutoHotkey scripting language?

 

Since i know nothing about this scripting language, can anybody help me with that?

 

Thanks a lot!



Armisius
  • Members
  • 8 posts
  • Last active: Feb 23 2018 06:25 PM
  • Joined: 17 Jan 2013

don't mind if its the master volume instead of youtube's volume?



Armisius
  • Members
  • 8 posts
  • Last active: Feb 23 2018 06:25 PM
  • Joined: 17 Jan 2013

Hey roineust, I just made one for you, it check if the active window is from youtube's website and then, if it is, it let you to change master volume with keys "U" and "D", check it.

 

~u::
WinGetActiveTitle,title ;gets the active window's name
IfInString, title,- youtube ;checks if the active window is youtube
{
	SoundSet,+10 ;if it is, raises the volume by 10
}
return
~d::
WinGetActiveTitle,title ;gets the active window's name
IfInString, title,- youtube ;checks if the active window is youtube
{
	SoundSet,-10 ;if it is, lowers the volume by 10
}
return

Have Fun :)



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

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.