AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Vista / Windows 7 Simple Volume Control

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
mrfantastic



Joined: 24 Sep 2009
Posts: 1

PostPosted: Thu Sep 24, 2009 11:19 am    Post subject: Vista / Windows 7 Simple Volume Control Reply with quote

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.



Code:

#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


Last edited by mrfantastic on Sat Jan 23, 2010 10:22 am; edited 1 time in total
Back to top
View user's profile Send private message
n00ge



Joined: 28 Sep 2007
Posts: 37

PostPosted: Sun Sep 27, 2009 8:21 pm    Post subject: Reply with quote

Your script works great. Thanks.
Back to top
View user's profile Send private message
zavjah



Joined: 01 Jul 2008
Posts: 13

PostPosted: Thu May 06, 2010 6:40 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
TheLeO



Joined: 11 Jun 2005
Posts: 264
Location: England ish

PostPosted: Sun Jan 30, 2011 8:03 pm    Post subject: Reply with quote

I adore your work!

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

Thanks
_________________
::
I Have Spoken
::
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Void



Joined: 16 Jun 2011
Posts: 9
Location: Sweden

PostPosted: Thu Jun 23, 2011 11:08 am    Post subject: Reply with quote

Awesome script. Could you implement a mute hotkey too?
Back to top
View user's profile Send private message
sumon



Joined: 18 May 2010
Posts: 1016
Location: Sweden

PostPosted: Thu Jun 23, 2011 11:37 am    Post subject: Reply with quote

Void wrote:
Awesome script. Could you implement a mute hotkey too?


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

Code:
VA_SetMute(True)
Back to top
View user's profile Send private message Visit poster's website
Void



Joined: 16 Jun 2011
Posts: 9
Location: Sweden

PostPosted: Thu Jun 23, 2011 12:06 pm    Post subject: Reply with quote

sumon wrote:
Void wrote:
Awesome script. Could you implement a mute hotkey too?


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

Code:
VA_SetMute(True)


Thank u Smile Modified it to work as a toggle key adding:
Code:
Insert::
  toggle:=!toggle
  if toggle
    VA_SetMute(True)
  Else
    VA_SetMute(False)
return
Back to top
View user's profile Send private message
nimda



Joined: 26 Dec 2010
Posts: 3856
Location: Awesometown, USA

PostPosted: Thu Jun 23, 2011 3:15 pm    Post subject: Reply with quote

Code:
VA_SetMute(toggle := !toggle)

_________________
Spam. Autoclick. Rapidfire.Window Control ToolsLicense
Back to top
View user's profile Send private message
Void



Joined: 16 Jun 2011
Posts: 9
Location: Sweden

PostPosted: Thu Jun 23, 2011 3:17 pm    Post subject: Reply with quote

nimda wrote:
Code:
VA_SetMute(toggle := !toggle)


nice ty Very Happy
Back to top
View user's profile Send private message
pantheon
Guest





PostPosted: Mon Jun 27, 2011 8:53 am    Post subject: Reply with quote

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 Smile
Back to top
Shurane
Guest





PostPosted: Mon Jul 18, 2011 5:03 am    Post subject: Reply with quote

Very useful, must say. The OSD volume display is a nice touch, especially.
Back to top
JerryR
Guest





PostPosted: Wed Aug 03, 2011 1:23 pm    Post subject: can't get volume hotkeys to work Reply with quote

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
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group