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