Jump to content

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

Very nice, simple, but good-looking volume control


  • Please log in to reply
8 replies to this topic
wildmonkey182
  • Members
  • 1 posts
  • Last active: Jul 21 2006 06:42 AM
  • Joined: 21 Jul 2006
This script uses #Up/Down/Right to move volume up/down or mute, unmute. It indicates the level of volume with a speaker icon next to a horizontal bar graph.

#Up causes volume to go up
#Down makes it go down
#Right mutes and unmutes

On my computer, I switch these controls to my keyboard's volume up/down/mute buttons. If you want to switch the controls to another button or key, simply replace the #Up/Down/Right with the keycode for the desired key.

Edit this line of the script (It's the 8th line from the bottom) if you want to change the position of the volume bar:
Gui, Show, NoActivate x720 y460 h48 w213, volume

Edit the number following "x" to change horizontal position and the number following "y" to change vertical position. x0 y0 is the absolute upper left corner of your screen, so for every increase in x, the volume bar moves right, and for every increase in y, it moves down.
I have to give the real credit for this script to Dactilus. I basically took his script from the topic "Volume control (with small GUI)" and tweaked it by switching orientation from vertical to horizontal and removing the mic on/off indicator. Dactilus, your script was the best I found on these forums, good job and thanks.

Here's the script:

;#NoTrayIcon 

#Up:: 
SoundSet +3 
SoundSet, +3, wave 
gosub, vupdt 
return 

#Down:: 
SoundSet -3 
SoundSet, -3, wave 
gosub, vupdt 
return 

#Left:: 
SoundSet, -0, Microphone, mute 
IfWinExist, volume 
{ 
SoundGet, m_m, Microphone, mute 
if m_m = On 
GuiControl,, R, 0 
else 
GuiControl,, R, 1 
SetTimer,label, 2000 
return 
} 
Gosub, show 
Return 

#Right:: 
SoundSet, -0, MASTER, mute 
IfWinExist, volume 
{ 
SoundGet, v_m, master, mute 
if v_m = On 
GuiControl,, Pic1,*icon40 C:\WINDOWS\system32\mmsys.cpl 
else 
GuiControl,, Pic1, *icon1 C:\WINDOWS\system32\mmsys.cpl 
SetTimer,label, 2000 
return 
} 
Gosub, show 
Return 
;This routine is isolated to avoid icon flashing 
vupdt: 
IfWinExist, volume 
{ 
SoundGet, master_volume 
GuiControl,, MP, %master_volume% 
SetTimer,label, 2000 
return 
} 
Gosub, show 
Return 

show: 
SoundGet, master_volume 
SoundGet, m_m, Microphone, mute 
SoundGet, v_m, master, mute 

IfWinNotExist, volume 
{ 
Gui, +ToolWindow -Caption +0x400000 +alwaysontop 
Gui, Add, GroupBox, x3 y2 w40 h45 cblack,
Gui, Add, text, x97 y2 ,Volume: 
Gui, Add, Progress,horizontal vMP x48 y18 w160 h20 c333cc,%master_volume%  
if v_m = On 
Gui, Add, pic, x7 y13 vPic1 icon40, C:\WINDOWS\system32\mmsys.cpl 
else 
Gui, Add, pic, x7 y13 vPic1 icon1, C:\WINDOWS\system32\mmsys.cpl 
if m_m = On 
GuiControl,, R, 0 
else 
GuiControl,, R, 1 
Gui, Show, NoActivate x720 y460 h48 w213, volume 
} 
SetTimer,label, 2000 
return 

label: 
SetTimer,label, off 
Gui, destroy


robiandi
  • Guests
  • Last active:
  • Joined: --
- Dactilus has a checkbox R, but you havn't. Therefore it makes no sense to put
GuiControl,,R,1
- It is always better to use %a_windir% ( and not C:\windows; I have c:\winnt )
- In Win2000 there is no icon40 in mmsys.cpl , but icon36 for mute and icon1 for on

Beltesassar
  • Guests
  • Last active:
  • Joined: --
I really like this: simple and does exactly what you want: mute the volume, set it higher or lower. Very simple GUI, effective. Thanks a lot!

jak
  • Members
  • 159 posts
  • Last active: Dec 16 2010 11:26 PM
  • Joined: 28 Feb 2006
Hi - this is an excellent, simple, instantaneous, and good looking volume control :)
So of course I want to tweak it ;) Cant leave perfection alone, after all!

I changed the UP/DOWN arrow key controls to mouse wheel up/down.

But also I'm trying to tweak it so that, WHILE the volume on screen display is up on the screen, pressing up/down mousewheel (WITHOUT the hotkey), moves the bar. Right now, it needs the hotkey (windows key) depressed while I move the mousewheel, otherwise the volume does not change.

Cant get it to work... any ideas? I tried sticking wheelup/wheeldown control into the vpudt gosub section...

Granted, I'm a newbie at autohotkey scripts... :(

Thanks!

jak
  • Members
  • 159 posts
  • Last active: Dec 16 2010 11:26 PM
  • Joined: 28 Feb 2006
Nevermind! I solved this by simply replacing

"#Up"

with

"xbutton1 & wheelup::"

and same for Down.

While holding the back button on my 5 button mouse and scrolling the wheel, it now controls the volume. :D That solved the problem of how to avoid needing to keep a hotkey pressed on the keyboard.

  • Guests
  • Last active:
  • Joined: --
i run your script an after about 30ish seconds it exits by itself. anybody know whats wrong? I used the same script posted above expect i changed the # to ^ (Alt->control).

wd5gnr
  • Members
  • 3 posts
  • Last active: Apr 17 2007 03:21 AM
  • Joined: 08 Apr 2007
A little clean up and changed it to suit my setup. In particular, I like to use Shift-Wheel to go up and down, but I also have VolUp/VolDown keys and a mute button on the keyboard and I wanted them to display the same way. Note that the GUI now dynamically updates the mute graphic.

I haven't done any GUI yet, so this was a nice gentle introduction. Well done! (Oh, and I just patched it again to move to a fixed place relative to the bottom right corner of the screen instead of hardcoding the coordinate).

; Volume 
$Volume_Up::
+WheelUp::
  {
  Send {Volume_Up}
  Gosub, vupdt
  return
  }

$Volume_Down::
+WheelDown::
  {
  Send {Volume_Down}
  Gosub, vupdt
  return
  }

$Volume_Mute::
  {
  Send {Volume_Mute}
  Gosub, vupdt
  return
  }

; display volume bar
vupdt:
IfWinExist, ahkvolume
{
  SoundGet, master_volume
  SoundGet, v_m, master, mute
  GuiControl,, MP, %master_volume%
  if v_m = On
    GuiControl,, Pic1, *Icon40 %a_windir%\system32\mmsys.cpl
  else 
    GuiControl,, Pic1, *Icon1 %a_windir%\system32\mmsys.cpl
  SetTimer,vclose, 2000
  return
}
SoundGet, master_volume
SoundGet, v_m, master, mute

IfWinNotExist, ahkvolume
{
  Gui, +ToolWindow -Caption +0x400000 +alwaysontop
  Gui, Add, GroupBox, x3 y2 w40 h45 cblack,
  Gui, Add, text, x97 y2 ,Volume:
  Gui, Add, Progress,horizontal vMP x48 y18 w160 h20 c333cc,%master_volume% 
  if v_m = On
    Gui, Add, pic, x7 y13 vPic1 icon40, %a_windir%\system32\mmsys.cpl
  else
    Gui, Add, pic, x7 y13 vPic1 icon1, %a_windir%\system32\mmsys.cpl
   SysGet, screenx, 0
   SysGet, screeny, 1
; adjust display to show in bottom right corner
  xpos:=screenx-275
  ypos:=screeny-100
  Gui, Show, NoActivate x%xpos% y%ypos% h48 w213, ahkvolume
}
SetTimer,vclose, 2000
return

vclose:
SetTimer,vclose, off
Gui, destroy
return


hithere
  • Guests
  • Last active:
  • Joined: --
I'm trying to set something up so that "line in" on my sound card is automatically un-muted on activation of a certain application, and muted on exit. I want it to work even if I enter the application with "mute" already active (i.e., I don't want a simple "toggle", I want it to check the status of mute and only send the "mute/un-mute" command if necessary to ensure that line-in isn't muted while the application is active, but is muted once the app is finished). Is there a way to automate this?

manvo
  • Guests
  • Last active:
  • Joined: --
Sorry for resurrecting a 2007 thread, i hope this can be useful to someone... :roll:

I have a pc which still uses Windows XP Professional (SP3) and i really liked this script!

I edited it to solve a bug i had: when muting the speaker icon exceeded window bounds.
I also removed the text label and re-organized things a bit.

Here is it:

;#NoTrayIcon

#Up::
  Send {Volume_Up}
  toggle_icon = 0
  Gosub, vmeter
  return

#Down::
  Send {Volume_Down}
  toggle_icon = 0
  Gosub, vmeter
  return

#Right::
  Send {Volume_Mute}
  toggle_icon = 1
  Gosub, vmeter
  return

; show volume meter
vmeter:
  SoundGet, master_volume
  SoundGet, volume_mute, master, mute
  IfWinExist, ahkvolume
  {
    GuiControl,, MP, %master_volume%
    if toggle_icon = 1
    {
      if volume_mute = On
        GuiControl,, Pic1, *Icon40 %a_windir%\system32\mmsys.cpl
      else
        GuiControl,, Pic1, *Icon1 %a_windir%\system32\mmsys.cpl
    }
  }
  else
  {
    Gui, +ToolWindow -Caption +0x400000 +alwaysontop
    Gui, Add, GroupBox, x3 y0 w40 h45 cblack
    Gui, Add, Progress,horizontal vMP x49 y16 w160 h20 c333cc,%master_volume%
    if volume_mute = On
      Gui, Add, pic, x7 y11 w32 h32 vPic1 icon40, %a_windir%\system32\mmsys.cpl
    else
      Gui, Add, pic, x7 y11 w32 h32 vPic1 icon1, %a_windir%\system32\mmsys.cpl
    Gui, Show, NoActivate x630 y400 h50 w212, ahkvolume
  }
  SetTimer,vmeterclose, 2000
  return

vmeterclose:
  SetTimer,vmeterclose, off
  Gui, destroy
  return