Jump to content

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

Vista / Windows 7 Simple Volume Control


  • Please log in to reply
14 replies to this topic
mrfantastic
  • Members
  • 1 posts
  • Last active: Sep 26 2009 08:39 AM
  • Joined: 24 Sep 2009
Based on paftdunk's Volume OSD.

Requires COM and VA libraries to work properly. Simply download appropriate .ahk files and put them into your ...\AutoHotkey\Lib\ folder.

Simple Volume Control increases or decreases master volume using following hotkeys:
- Media Volume Up / Media Volume Down
- Win+UpArrow / Win+DownArrow
- MouseButton5+MouseScrollUp / MouseButton5+MouseScrollDown

When you set master volume to 0 it actually mutes all sounds, because Windows 7, for some strange reason, keeps playing music even if you set master volume to 0.

That's it. This script doesn't do anything else :wink:.

Feel free to customize it in any way you want. Tested on Windows 7 x64 build 7100.

Posted Image

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SetBatchLines -1

COM_Init()
vol_Master := VA_GetMasterVolume()

; -------------------
; START CONFIGURATION
; -------------------
; The percentage by which to raise or lower the volume each time
vol_Step = 3
; How long to display the volume level bar graphs (in milliseconds)
vol_DisplayTime = 1000
; Transparency of window (0-255)
vol_TransValue = 255
; Bar's background colour
vol_CW = EEEEEE    
vol_Width = 200  ; width of bar
vol_Thick = 20   ; thickness of bar
; Bar's screen position
vol_PosX := A_ScreenWidth - vol_Width - 50
vol_PosY := A_ScreenHeight - vol_Thick - 100
; --------------------
; END OF CONFIGURATION
; --------------------
vol_BarOptionsMaster = 1:B1 ZH%vol_Thick% ZX8 ZY4 W%vol_Width% X%vol_PosX% Y%vol_PosY% CW%vol_CW%
return


$Volume_down::
#Down::
~XButton2 & WheelDown:: 
{
   if vol_Master > .01
   {
   VA_SetMasterVolume(vol_Master-=vol_Step)
   if vol_Master <= 0
      {
         VA_SetMute(True)
      }
   }
Gosub, vol_ShowBars
}
return



$Volume_up::
#Up::
~XButton2 & WheelUp::
{
   if vol_Master <= 99
   {
   VA_SetMasterVolume(vol_Master+=vol_Step)
   if vol_Master > 1
      {
         VA_SetMute(False)
      }
   }
Gosub, vol_ShowBars
}
return



vol_ShowBars:
; Get volumes in case the user or an external program changed them:
vol_Master := VA_GetMasterVolume()
vol_Mute := VA_GetMasterMute()
if vol_Mute <> 1
{
  vol_Colour = Green    
  vol_Text = Volume
}
else
{
  vol_Colour = Red      
  vol_Text = Volume (muted)
}
; To prevent the "flashing" effect, only create the bar window if it doesn't already exist:
IfWinNotExist, VolumeOSDxyz
{
    Progress, %vol_BarOptionsMaster% CB%vol_Colour% CT%vol_Colour%, , %vol_Text%, VolumeOSDxyz
    WinSet, Transparent, %vol_TransValue%, VolumeOSDxyz
}
Progress, 1:%vol_Master%, , %vol_Text%
SetTimer, vol_BarOff, %vol_DisplayTime%
return


vol_BarOff:
SetTimer, vol_BarOff, off
Progress, 1:Off
return


n00ge
  • Members
  • 37 posts
  • Last active: Jul 20 2010 10:49 PM
  • Joined: 28 Sep 2007
Your script works great. Thanks.

zavjah
  • Members
  • 13 posts
  • Last active: Mar 13 2013 09:51 AM
  • Joined: 01 Jul 2008
Hi mrfantastic,

Cool job. Thanks for the code.

Is there a way to force a change of the script icon when master volume is muted, to signaliez it all the time. As soon the volume differ from 0, then the icon should chang back.
Thanks,
zuvjah

______________________________________________________________________
Still a beginner but I love the AHK

TheLeO
  • Members
  • 264 posts
  • Last active: Jan 02 2012 01:51 AM
  • Joined: 11 Jun 2005
I adore your work!

I've been looking for something simple that just works. Perfect!

Thanks
::
I Have Spoken
::

Void
  • Members
  • 9 posts
  • Last active: Jul 18 2011 01:47 PM
  • Joined: 16 Jun 2011
Awesome script. Could you implement a mute hotkey too?

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Awesome script. Could you implement a mute hotkey too?


Edit the script to include this line below a hotkey of your choice:

VA_SetMute(True)


Void
  • Members
  • 9 posts
  • Last active: Jul 18 2011 01:47 PM
  • Joined: 16 Jun 2011

Awesome script. Could you implement a mute hotkey too?


Edit the script to include this line below a hotkey of your choice:

VA_SetMute(True)


Thank u :) Modified it to work as a toggle key adding:
Insert::
  toggle:=!toggle
  if toggle
    VA_SetMute(True)
  Else
    VA_SetMute(False)
return


nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
VA_SetMute(toggle := !toggle)


Void
  • Members
  • 9 posts
  • Last active: Jul 18 2011 01:47 PM
  • Joined: 16 Jun 2011

VA_SetMute(toggle := !toggle)


nice ty :D

pantheon
  • Guests
  • Last active:
  • Joined: --
Hello,

Thank you for your script !

My problem is :
I have 2 cards sounds :
- C-Media PCI Audio Device (default)
- Realtek High Definition Audio

I would like to modify volume of my second card sound (Realtek High Definition Audio). Is it possible ?

PS : I must keep C-Media in default card sound.

Thank you for your help :)

Shurane
  • Guests
  • Last active:
  • Joined: --
Very useful, must say. The OSD volume display is a nice touch, especially.

JerryR
  • Guests
  • Last active:
  • Joined: --
Hi, Can you tell me which autohotkey program and which COM file I should use? I have Windows 7, 64 bit. I've tried two or three of the volume hotkey scripts and can't get any to work. If they work at all, they just turn the volume all the way down, no matter whcih keystroke I press. So, I thought at least I would make sure I have the right stuff first.
Thank you. Jerry

  • Guests
  • Last active:
  • Joined: --
Mine says there's a problem with the "COM_Init()" line. I'm new to this so I didn't mess with anything and I'm not sure how to fix it.

Here's a screenshot:

<!-- m -->http://goo.gl/st7ia<!-- m -->

http://goo.gl/st7ia

Philister
  • Members
  • 57 posts
  • Last active: Sep 27 2016 08:10 PM
  • Joined: 12 Feb 2012
Apparently, this script doesn't work with Autohotkey_L, see here: http://www.autohotke...php?f=1&t=87024.

Could somebody please finally fix SoundSet so it works with Windows7?! That's just sooo basic.

rjcervantes
  • Members
  • 1 posts
  • Last active: Nov 27 2012 09:45 AM
  • Joined: 27 Nov 2012
This script works for me perfect. I'm running Windows 7 64 bit. I did run into some issues which I will address now.

COM_Init()

When I first ran the script I received an error regarding the initialization of the COM. Apparently COM is now integrated into the program and the line is unneeded. I deleted the line and it solved the problem.


VA_Library

Long story short, you need the VA_Library and you must have it in a folder called "Lib" and (most importantly) have that folder in the same directory as your script.


Put this code on top

My last issue was confusing. When I added this code to a preexisting AHK file I pasted it below a few run commands. It didn't work. So I cut the code, pasted it on top of everything and it worked fine. I'm not really a strong programmer (yet), so this might be a no brainer for the rest of you.