Volume Control Slider

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jrachr
Posts: 532
Joined: 01 Mar 2021, 17:33

Volume Control Slider

Post by jrachr » 20 Feb 2022, 09:07

Hi . Attached is a copy of a code I found that When alt right or alt left arrows are pressed shows a slider on screen with the volume. My question is if I wanted to change the color of the bar from green to something else ie red,blue,etc. Is it possible? I have looked in the script and see nowhere to make a change. If someone could point me the right direction I would appreciate it.

Code: Select all

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

SoundGet,Volume
Volume:=Round(Volume)
TrayTip:="Alt+LeftArrow or Alt+RightArrow to adjust volume" . "`nCurrent Volume=" . Volume
Menu, Tray, Icon, C:\Users\Jr\Desktop\Icons\Icons-Land-Vista-Multimedia-Volume-2.ico          ;get tray icon from Icons
Return

!Left::
SetTimer,SliderOff,3000
SoundSet,-1
Gosub,DisplaySlider
Return

!Right::
SetTimer,SliderOff,3000
SoundSet,+1
Gosub,DisplaySlider
Return

SliderOff:
Progress,Off
Return

DisplaySlider:
SoundGet,Volume
Volume:=Round(Volume)
Progress,%Volume%,%Volume%,Volume,HorizontalVolumeSliderW10
TrayTip:="Alt+LeftArrow or Alt+RightArrow to adjust volume" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Volume Control Slider

Post by mikeyww » 20 Feb 2022, 09:33

Code: Select all

color = Blue
Gui, Font, s10 w700
Gui, Add, Text    , w300 Center        , Volume
Gui, Add, Progress, wp   h20    vvol     c%color%
Gui, Font, w400
Gui, Add, Text    , wp   Center vvolText

!Left::
!Right::
SoundSet, % Instr(A_ThisHotkey, "L") ? -1 : "+1"
SoundGet, Volume
GuiControl,, vol,     % Volume
GuiControl,, volText, % Round(Volume)
Gui, Show,, HorizontalVolumeSliderW10
SetTimer, GuiEscape, -1500
Return
GuiEscape:
Gui, Hide
Return
Last edited by mikeyww on 20 Feb 2022, 09:47, edited 1 time in total.

Rohwedder
Posts: 7555
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Volume Control Slider

Post by Rohwedder » 20 Feb 2022, 09:47

Hallo,
or:

Code: Select all

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

SoundGet,Volume
Volume:=Round(Volume)
TrayTip:="Alt+LeftArrow or Alt+RightArrow to adjust volume" . "`nCurrent Volume=" . Volume
Menu, Tray, Icon, C:\Users\Jr\Desktop\Icons\Icons-Land-Vista-Multimedia-Volume-2.ico          ;get tray icon from Icons
Return

!Left::
SetTimer,SliderOff,3000
SoundSet,-1
Gosub,DisplaySlider
Return

!Right::
SetTimer,SliderOff,3000
SoundSet,+1
Gosub,DisplaySlider
Return

SliderOff:
Progress,Off
Return

DisplaySlider:
SoundGet,Volume
Volume:=Round(Volume)
Progress, CBFF0000 ; RGB=Red: R=FF G=00 B=00
Progress,%Volume%,%Volume%,Volume,HorizontalVolumeSliderW10
TrayTip:="Alt+LeftArrow or Alt+RightArrow to adjust volume" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Volume Control Slider

Post by mikeyww » 20 Feb 2022, 09:49

I would recommend a negative timer frequency.

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

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 10:16

I suggest looking at this thread:
viewtopic.php?f=76&t=47784

My latest script is in this post:
viewtopic.php?f=76&t=47784&start=40#p386832

If you don't want the different color sliders when muted and unmuted, use the script before that one:
viewtopic.php?f=76&t=47784&start=40#p386762

If you don't want the mute future, use the script before that one:
viewtopic.php?p=235750#p235750

Regards, Joe

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 10:48

@JoeWinograd Hi Joe. As you can see what I have is your Horizontal Volume Slider. For me this is ideal. I downloaded a couple of your newer Sliders you suggested but see no slider when I press the numpad +/_ buttons. The volume does go up and down but no slider like in your previous version. I would just like the ability to change color of slider from green to something else if possible. Not really a big deal. Am I missing something or is there just no way to change the color. And the thought of having multiple colors for when it muted or unmuted sounds interesting. Tk's for creating such a great script.

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

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 11:24

Hi @jrachr,

> As you can see what I have is your Horizontal Volume Slider.

Yes, I noticed that. :)

> I downloaded a couple of your newer Sliders you suggested but see no slider when I press the numpad +/_ buttons.

I just downloaded the latest one from here:
viewtopic.php?f=76&t=47784&start=40#p386832

I did not change anything after downloading it...just ran it...works perfectly! Hitting NumpadMult toggles mute. Hitting NumpadAdd and NumpadSub when muted gives this:

after hitting numpad add or sub when muted.png
after hitting numpad add or sub when muted.png (2.46 KiB) Viewed 3033 times

Hitting them when unmuted gives this:

after hitting numpad add or sub when unmuted.png
after hitting numpad add or sub when unmuted.png (2.44 KiB) Viewed 3033 times

If you download that script and run it as is, it should work fine. Please try it and let me know what happens. I'm confident that we can get it working for you.

> Tk's for creating such a great script.

You're very welcome...I appreciate the compliment! Regards, Joe

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 11:45

@Joewinograd. Hi Joe. Tried it again and while volume does mute , and volumes go up and down with numpad +/_ buttons there is no slider bar on screen. Attached is the code that does show slider bar when volume up/down id called. Works fine. Just no option to change color. Your new one looks interesting but doesn't work on my windows 11. Don't know why one version would work but not your new one. Interesting. Even if I use one that works is there a way to change slider bar color? Color for up and color for down? Tk's for your help.

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 11:46

This does work.

Code: Select all

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

SoundGet,Volume
Volume:=Round(Volume)
TrayTip:="LCtrl + = or LCtrl + - to adjust volume" . "`nCurrent Volume=" . Volume
Menu, Tray, Icon, C:\Users\Jr\Desktop\Icons\Icons-Land-Vista-Multimedia-Volume-2.ico          ;get tray icon from Icons
Return

^=::
SetTimer,SliderOff,3000
SoundSet,+5
Gosub,DisplaySlider
Return

^-::
SetTimer,SliderOff,3000
SoundSet,-5
Gosub,DisplaySlider
Return

SliderOff:
Progress,Off
Return

DisplaySlider:
SoundGet,Volume
Volume:=Round(Volume)
Progress,%Volume%,%Volume%,Volume,HorizontalVolumeSliderW10
TrayTip:="LCtrl + = or LCtrl + - to adjust volume" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return

User avatar
mikeyww
Posts: 26602
Joined: 09 Sep 2014, 18:38

Re: Volume Control Slider

Post by mikeyww » 20 Feb 2022, 11:52

The only thing that I note here is that Progress is a deprecated command and not recommended for new scripts. I suppose it does not matter if the script works.

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

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 12:23

jrachr wrote:doesn't work on my windows 11
Here's my guess: the BarXlocation and BarYlocation values are bad for your W11 system. Change them to smaller numbers, such as:

Code: Select all

BarXlocation:="x100"
BarYlocation:="y200"
It will almost surely work then.

I could base the size on A_ScreenWidth and A_ScreenHeight, but different users may want it in different locations. You could center it with this (does not take into account size or position of taskbar):

Code: Select all

BarXlocation:=((A_ScreenWidth-BarWidth)/2)
BarYlocation:=((A_ScreenHeight-BarHeight)/2)
I tested both sets of code above in W11...worked perfectly! Here's a screenshot from the centering code:

horiz vol slider center w11.png
horiz vol slider center w11.png (46.68 KiB) Viewed 2893 times

Regards, Joe
Last edited by JoeWinograd on 20 Feb 2022, 12:49, edited 1 time in total.

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 12:49

K. Will try it out when I get home. Tks

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

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 12:50

OK...I just added a screenshot to my previous post...from a W11 system with the centering code. Regards, Joe

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 13:13

@Joewinograd. K. Working now. But is there no option to change green to another color when changing volumes. See where it changes to red when muted but would like to have an option if possible. Tks for all your help.
@mikeyww. @ rohwedder Tks for all your help.

Cheer's

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 13:29

Hi All. Please overlook last post. I found color change in script. Thank you very much for all your help.

@JoeWinograd. Very nice script. If you ever continue to decide and play with it. Adding an option for colors to be different as volume goes up(maybe green) and volume down(Maybe red) with option to change color would be nice. But trust me this script is fine just the way it is. Tk's again for all your work.

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

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 13:42

jrachr wrote:Working now.
Glad to hear it!

The current code has a variable for the bar color when muted (BarColorMuted) and one when unmuted (BarColorUnmuted). I considered automatically unmuting whenever the volume is increased or decreased, but decided that a user may want to adjust the volume without necessarily unmuting at that time. Also, if I unmute whenever the volume is increased or decreased, you will never see the muted color! That said, is this what you want, i.e., automatically unmuting (and, therefore, changing the bar to the unmuted color) whenever you increase or decrease the volume? Regards, Joe

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 13:57

@Joewinograd. This will be fine Joe. As I said if somewhere down the road ty here is an option for different colors for up and down volumes that would be nice but this works. Tk's again. Cheer's

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

Re: Volume Control Slider

Post by JoeWinograd » 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

; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=100621#p446914

; Joe Winograd 20-Feb-2022
; Developed for Windows 10, but tested successfully on W7, W8.1, W10, W11 (all 64-bit)
; Updated 10-Mar-2021:
;   Added Toggle Mute feature
;   Changed to Red and Green sliders for Muted and Unmuted states
; 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
; Updated 25-Sep-2022:
;   Fixed bug where timer was not turned off when slider was turned off

#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:=10
VolumeIncrement:=1
; 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:
SetTimer,,Off
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
Last edited by JoeWinograd on 25 Sep 2022, 12:30, edited 3 times in total.

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

Re: Volume Control Slider

Post by jrachr » 20 Feb 2022, 14:22

@JoeWinograd. Perfect Joe. Works like a charm. Thank's again for all your trouble. Cheer's

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

Re: Volume Control Slider

Post by JoeWinograd » 20 Feb 2022, 14:49

jrachr wrote:Works like a charm.
Great news! You're very welcome. Cheers, Joe

Post Reply

Return to “Ask for Help (v1)”