Volume Control Slider

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2179
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 17:06

Just modified the script in my previous post to make the bar width one-third the screen width, thereby avoiding another hard-coded value. The only hard-coded value now is the bar height. Also, fixed the missing X and Y on the Gui,Show, and added some Round calls. Regards, Joe

weeuweed
Posts: 1
Joined: 31 May 2022, 21:51

Re: Volume Control Slider

Post by weeuweed » 31 May 2022, 21:57

JoeWinograd wrote:
20 Feb 2022, 14:08
jrachr wrote:colors to be different as volume goes up(maybe green) and volume down(Maybe red)
Our posts crossed.

That's an interesting idea. Below is a revision of the script with three changes:

(1) Bar-centering and width based on screen width and height.

(2) Automatically unmuting whenever you increase or decrease the volume.

(3) When you increase the volume, the bar is the color in the BarColorIncreasing variable (set to Green in code below). When you decrease the volume, the bar is the color in the BarColorDecreasing variable (set to Red in code below).

Regards, Joe

Code: Select all

; Joe Winograd 20-Feb-2022
; Developed for Windows 10, but tested successfully on W7, W8.1, W10, W11 (all 64-bit)
; Updated with Toggle Mute feature 10-Mar-2021
; Updated with Red and Green sliders for Muted and Unmuted states 10-Mar-2021
; Updated 20-Feb-2022:
;   Red and Green sliders when decreasing and increasing volume (no longer for muted/unmuted)
;   Automatically unmuting when decreasing and increasing volume
;   X coordinate and bar width based on screen width
;   Y coordinate based on screen height

#Warn,UseUnsetLocal
#NoEnv
#SingleInstance force
SetBatchLines,-1

; begin values to change
BarHeight:=20
BarWidth:=Round(A_ScreenWidth/3)
BarXlocation:=Round((A_ScreenWidth-BarWidth)/2)
BarYlocation:=Round((A_ScreenHeight-BarHeight)/2)
BarColorDecreasing:="Red"
BarColorIncreasing:="Green"
BarMillisecondsToStayOnScreen:=3000 ; 3 seconds
;HotkeyVolumeDown:="!Left"
;HotkeyVolumeUp:="!Right"
;HotkeyToggleMute:="!^m"
HotkeyVolumeDown:="NumpadSub"
HotkeyVolumeUp:="NumpadAdd"
HotkeyToggleMute:="NumpadMult"
;VolumeIncrement:=1
VolumeIncrement:=10
; end values to change

SplitPath,A_ScriptName,,,,ProgramName
Hotkey,%HotkeyVolumeDown%,VolumeDown
Hotkey,%HotkeyVolumeUp%,VolumeUp
Hotkey,%HotkeyToggleMute%,ToggleMute
SoundGet,Volume
Volume:=Round(Volume)
TrayTip:=HotkeyVolumeDown . " or " . HotkeyVolumeUp . " to adjust volume" . "`n" . HotkeyToggleMute . " to toggle mute" . "`nCurrent Volume=" . Volume
TrayIconFile:=A_WinDir . "\System32\shell32.dll" ; get tray icon from shell32.dll
TrayIconNum:="-225" ; use music note as tray icon (icon 225 in shell32)
Menu,Tray,Tip,%TrayTip%
Menu,Tray,Icon,%TrayIconFile%,%TrayIconNum%
Gui,+ToolWindow -SysMenu
Gui,Add,Progress,w%BarWidth% h%BarHeight% c%BarColor% vBarVal
Gui,Hide
Return ; end auto-execute

VolumeDown:
SoundSet,0,,Mute ; unmute
BarColor:=BarColorDecreasing
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,-%VolumeIncrement%
Gosub,DisplaySlider
Return

VolumeUp:
SoundSet,0,,Mute ; unmute
BarColor:=BarColorIncreasing
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,+%VolumeIncrement%
Gosub,DisplaySlider
Return

ToggleMute:
SoundSet,+1,,Mute ; toggle the mute setting
Return

SliderOff:
Gui,Hide
Return

DisplaySlider:
SoundGet,Volume
Volume:=Round(Volume)
Title:=ProgramName . "     Current Volume=" . Volume
Gui,Show,x%BarXlocation% y%BarYlocation%,%Title%
GuiControl,,BarVal,%Volume%
GuiControl,+c%BarColor%,BarVal
TrayTip:=HotkeyVolumeDown . " or " . HotkeyVolumeUp . " to adjust volume" . "`n" . HotkeyToggleMute . " to toggle mute" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return
Hi Joe, registered just to thank you. This is brilliant, exactly what i needed :beer:

User avatar
JoeWinograd
Posts: 2179
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Volume Control Slider

Post by JoeWinograd » 31 May 2022, 23:01

weeuweed wrote:registered just to thank you
Hi weeuweed,
You're welcome, and thanks back to you for taking the time to register just to thank me...I really appreciate that! I'm glad the script is what you need. Regards, Joe

User avatar
JoeWinograd
Posts: 2179
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Volume Control Slider

Post by JoeWinograd » 25 Sep 2022, 12:31

For anyone using the script above, I just fixed a bug in it where the timer was not turned off when the slider was turned off. Regards, Joe

jrachr
Posts: 532
Joined: 01 Mar 2021, 17:33

Re: Volume Control Slider

Post by jrachr » 27 Sep 2022, 14:44

@Joe Thank you very much for the update Joe.Sorry for late response.Had no power or internet because of hurricane up here.Thanks again.

User avatar
JoeWinograd
Posts: 2179
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Volume Control Slider

Post by JoeWinograd » 28 Sep 2022, 10:51

Hi Jr,
I saw that the hurricane went up your way. I hope you and your family came out of it well. Regards, Joe

jrachr
Posts: 532
Joined: 01 Mar 2021, 17:33

Re: Volume Control Slider

Post by jrachr » 28 Sep 2022, 15:55

@Joe. Other than no power for a couple of days and no cable or internet we did ok.Lol.You don't realize how naked you are until you have no internet. Just wrong.But all good now. Tk's for asking.

garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: Volume Control Slider

Post by garry » 29 Sep 2022, 03:28

@jrachr glad it's all over ... here some links , weather / hurricane
viewtopic.php?f=17&t=52&p=484580#p484580

nelvin08
Posts: 97
Joined: 27 Mar 2022, 23:13

Re: Volume Control Slider

Post by nelvin08 » 19 Feb 2023, 00:33

Hi @JoeWinograd

Thank you so much for your script. I have it working on my end.

But it begs the question, how do I include a microphone mute hotkey in the script?

Yes, it mutes my speakers. But can we also apply this script for day to day meetings (microphone control) for example?
Last edited by nelvin08 on 19 Feb 2023, 01:24, edited 1 time in total.

User avatar
JoeWinograd
Posts: 2179
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Volume Control Slider

Post by JoeWinograd » 19 Feb 2023, 01:08

nelvin08 wrote:I have it working on my end.
Glad to hear it!
nelvin08 wrote:microphone mute
Here's a forum thread on that (and a search for "microphone mute" will get others):
viewtopic.php?f=6&t=15509

I've made no attempt to integrate that (or any mic-mute code) with my volume control script, but it should be doable. Regards, Joe

nelvin08
Posts: 97
Joined: 27 Mar 2022, 23:13

Re: Volume Control Slider

Post by nelvin08 » 19 Feb 2023, 01:46

I swear I tried this one earlier and it didn't work.

Maybe I was getting the wrong ID then. All good now.

I was actually playing with it and since the SoundSet only works for only 1 device (I assume), I tried the below code so whatever mic I am using (since I might be switching from time to time), it mutes and unmutes both.

There's no harm in doing this right?

Code: Select all

!`::
SoundSet, +1, MASTER, Mute, 16
SoundSet, +1, MASTER, Mute, 19
return

Post Reply

Return to “Ask for Help (v1)”