Custom volume control with custom GUI

Post your working scripts, libraries and tools for AHK v1.1 and older
a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Custom volume control with custom GUI

Post by a0l0e0x000 » 02 Feb 2021, 17:45

I like to adjust volume with my mouse's programmable buttons and have been getting annoyed by
a) "send, {volume_up}" because it displays Windows's annoying overlay in the top left
b) "SoundSet, +4" because it doesn't indicate to me how loud the sound is at all

So I took the Gui example #6 form ahk's documentation page and adapted it, then used it in combination with "SoundSet" to make a surprisingly robust script for volume control. It is also very customizable (you can easily change the hotkeys, change the colors by editing hex values, change the size of steps, change the position on the screen (you may need to do this as my monitor is 21:9 3440x1440), text size...)

You have to change All of the "Keywait, Ctrl" into "Keywait, your_hotkey" if you change the hotkey for it to work properly.

Code: Select all

^NumpadMult::
soundset, -4
#singleinstance, force
CustomColor := "000000"  ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s100 bold  ; Set a large font size (32-point).
Gui, Add, Text, vMyText cLime, XXXXX YYYYY  ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x1470 y1000 NoActivate  ; NoActivate avoids deactivating the currently active window.
Keywait, Ctrl
Keywait, Ctrl, d T1
Gui, destroy
return

^Numpad8::
soundset, +4
#singleinstance, force
CustomColor := "000000"  ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s100 bold  ; Set a large font size (32-point).
Gui, Add, Text, vMyText cLime, XXXXX YYYYY  ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x1470 y1000 NoActivate  ; NoActivate avoids deactivating the currently active window.
Keywait, Ctrl
Keywait, Ctrl, d T1
Gui, destroy
return

UpdateOSD:
Soundget, master_volume
master_volume := round(master_volume)
GuiControl,, MyText, %master_volume%
return

a0l0e0x000
Posts: 14
Joined: 26 Dec 2020, 08:27

Re: Custom volume control with custom GUI

Post by a0l0e0x000 » 16 Feb 2021, 09:37

Fixed: no error message if you press both buttons at the same time

Code: Select all

^NumpadMult::
soundset, -4
#singleinstance, force
CustomColor := "000000"  ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s100 bold  ; Set a large font size (32-point).
Gui, Add, Text, vMyText cLime, XXXXX YYYYY  ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x1470 y1000 NoActivate  ; NoActivate avoids deactivating the currently active window.
Keywait, Ctrl
Keywait, Ctrl, d T1
Gui, destroy
return

^Numpad8::
soundset, +4
#singleinstance, force
CustomColor := "000000"  ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow  ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s100 bold  ; Set a large font size (32-point).
Gui, Add, Text, vMyText2 cLime, XXXXX YYYYY  ; XX & YY serve to auto-size the window.
; Make all pixels of this color transparent and make the text itself translucent (150):
WinSet, TransColor, %CustomColor% 150
Gosub, UpdateOSD  ; Make the first update immediate rather than waiting for the timer.
Gui, Show, x1470 y1000 NoActivate  ; NoActivate avoids deactivating the currently active window.
Keywait, Ctrl
Keywait, Ctrl, d T1
Gui, destroy
return

UpdateOSD:
Soundget, master_volume
master_volume := round(master_volume)
GuiControl,, MyText, %master_volume%
GuiControl,, MyText2, %master_volume%
return

User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Custom volume control with custom GUI

Post by rommmcek » 17 Feb 2021, 11:48

I made some changes to your script:
Spoiler

Post Reply

Return to “Scripts and Functions (v1)”