Volume Control on PC Windows 10

Ask gaming related questions (AHK v1.1 and older)
LD50
Posts: 1
Joined: 25 Feb 2021, 14:44

Re: Volume Control on PC Windows 10

Post by LD50 » 25 Feb 2021, 14:53

Hi

Sorry to hikack this thread but it seemed better than starting a new thread on the same subject.

I have created a simple script for vol up and down with shift cursors:

Code: Select all

+Up::SoundSet,+10
+Down::SoundSet,-10
Return
I have this script sitting in a folder in the installation folder for autohotkey. It runs just fine.

I then created a shortcut to add to my startup folder (ProgramData>Microsoft>Windows>Start Menu>Programs>Startup) as I would like this script to run when I start windows. Is this the correct procedure? It is appearing in msconfig.

Also somewhat of a noob to windows scripting (have some experience with Xhtml/PHP)
Last edited by BoBo on 25 Feb 2021, 15:43, edited 1 time in total.
Reason: Added [code][/code]-tags.

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 27 Feb 2021, 07:59

Hi LD50,

I see that this is your first post here, so let me start with...Welcome Aboard!
LD50 wrote:but it seemed better than starting a new thread on the same subject
I don't think so. Although the Subject is the same (Volume Control on PC Windows 10), you're asking a question about a different, specific script that you wrote, so a new question would have been preferable, imo.
LD50 wrote:shortcut to add to my startup folder
There are two startup folders...one for the logged-in user and one for all users. The startup folder you chose is the all-users (aka Public) one, which, btw, is in the AHK built-in variable A_StartupCommon. The user one is in the AHK built-in variable A_Startup (such as, C:\Users\<UserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup). Yes, placing the shortcut in either one will work to run the script when Windows starts.

Regarding your script, you used single-line hotkeys, i.e., the hotkey code is on the same line, immediately to the right of the double-colon. In that case, the Return is implicit, so you don't need the explicit Return command. I nearly always use the multi-line method to avoid future bugs when I add some code and forget the Return. :) In other words, this is preferable, imo:

Code: Select all

+Up::
SoundSet,+10
Return

+Down::
SoundSet,-10
Return
Regards, Joe

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 10 Mar 2021, 12:05

Inspired by a recent question at the forum, I added a Toggle Mute feature to my most recent script above. Here it is:

Code: Select all

; Joe Winograd 27-Aug-2018
; Developed for Windows 10, but tested successfully on W7, W8.1, and W10 (all 64-bit)
; Updated with Toggle Mute feature 10-Mar-2021
#Warn,UseUnsetLocal
#NoEnv
#SingleInstance force
SetBatchLines,-1

; begin values to change
BarWidth:="w800"
BarHeight:="h20"
BarXlocation:="x500"
BarYlocation:="y1200"
BarColor:="Blue"
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,%BarWidth% %BarHeight% c%BarColor% vBarVal
Gui,Hide
Return ; end auto-execute

VolumeDown:
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,-%VolumeIncrement%
Gosub,DisplaySlider
Return

VolumeUp:
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,%BarXlocation% %BarYlocation%,%Title%
GuiControl,,BarVal,%Volume%
TrayTip:=HotkeyVolumeDown . " or " . HotkeyVolumeUp . " to adjust volume" . "`n" . HotkeyToggleMute . " to toggle mute" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return
The addition of the HotkeyToggleMute hotkey and the supporting ToggleMute code should be easy to follow, but if you have any questions, I'll be happy to try to help. Regards, Joe

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 10 Mar 2021, 16:37

The Toggle Mute feature generated a new idea, i.e., have different color sliders when muted and unmuted. For example, instead of a blue slider in both states, have a red slider when muted and a green slider when unmuted. Here's the updated script:

Code: Select all

; Joe Winograd 27-Aug-2018
; Developed for Windows 10, but tested successfully on W7, W8.1, and W10 (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
#Warn,UseUnsetLocal
#NoEnv
#SingleInstance force
SetBatchLines,-1

; begin values to change
BarWidth:="w800"
BarHeight:="h20"
BarXlocation:="x500"
BarYlocation:="y1200"
BarColorMuted:="Red"
BarColorUnmuted:="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,%BarWidth% %BarHeight% c%BarColor% vBarVal
Gui,Hide
Return ; end auto-execute

VolumeDown:
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,-%VolumeIncrement%
Gosub,DisplaySlider
Return

VolumeUp:
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,+%VolumeIncrement%
Gosub,DisplaySlider
Return

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

SliderOff:
Gui,Hide
Return

DisplaySlider:
SoundGet,MuteState,,Mute
If (MuteState="Off")
  BarColor:=BarColorUnmuted
Else
  BarColor:=BarColorMuted
SoundGet,Volume
Volume:=Round(Volume)
Title:=ProgramName . "     Current Volume=" . Volume
Gui,Show,%BarXlocation% %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
Regards, Joe

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 20 Feb 2022, 17:21

For anyone interested, there's an updated version of the script here:

viewtopic.php?f=76&t=100621#p446914

Regards, Joe

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 10 Aug 2022, 13:29

JoeWinograd wrote:
24 Apr 2018, 11:29
Hi David,
It works perfectly here on W7 and W10. I suspect you copied it wrong or modified it wrong, although it could be something peculiar with your system. Let's try a different approach. I'm attaching the script to this post. I modified it to use the Ctrl key instead of Alt. Exit the script that's running now by right-clicking on the tray icon, then clicking Exit. Download the new script and run it. Regards, Joe
Hi Joe how can I remake this script so that only numbers are visible

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 10 Aug 2022, 13:39

dadaya7852 wrote:remake this script
Hi dadaya,
I see that this is your first post here, so let me start with...Welcome Aboard!

There are several scripts in this thread, including one linked to in a different thread. So, which script is it that you want to remake? Either post the script itself or provide a link to it. Regards, Joe

Edit on 15-Aug-2022: Although I haven't heard back from you on my question above, I figured out which script you're talking about based on the text that you quoted. It is the one attached to this post:

viewtopic.php?f=76&t=47784#p214624

When you say that you want to "remake this script so that only numbers are visible", I presume you mean that you don't want the word "Volume" or the horizontal green slider. For that, I changed the script to remove the Progress bar and add a Gui with a text control that contains the numbers for the volume...nothing else appears other than the numbers. The updated script is attached, and here is a GIF showing it working on a W10 system:

volumenumbersonlydemo.gif
volumenumbersonlydemo.gif (104.72 KiB) Viewed 2786 times

Regards, Joe

Edit on 16-Aug-2022: Minor script update and added demo GIF above.
Attachments
VolumeAdjustNumbersOnly.ahk
(967 Bytes) Downloaded 57 times

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 24 Sep 2022, 01:59

JoeWinograd wrote:
10 Aug 2022, 13:39
dadaya7852 wrote:remake this script
Hi dadaya,
I see that this is your first post here, so let me start with...Welcome Aboard!

There are several scripts in this thread, including one linked to in a different thread. So, which script is it that you want to remake? Either post the script itself or provide a link to it. Regards, Joe

Edit on 15-Aug-2022: Although I haven't heard back from you on my question above, I figured out which script you're talking about based on the text that you quoted. It is the one attached to this post:

viewtopic.php?f=76&t=47784#p214624

When you say that you want to "remake this script so that only numbers are visible", I presume you mean that you don't want the word "Volume" or the horizontal green slider. For that, I changed the script to remove the Progress bar and add a Gui with a text control that contains the numbers for the volume...nothing else appears other than the numbers. The updated script is attached, and here is a GIF showing it working on a W10 system:


volumenumbersonlydemo.gif


Regards, Joe

Edit on 16-Aug-2022: Minor script update and added demo GIF above.
Omg Joe thanks sorry for taking so long to reply, I completely forgot about this site. But when i use this script in games they just Alt+Tab or Win+D sorry for my english but in the previous script they were not switched to desktop

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 24 Sep 2022, 02:12

Hi @dadaya7852,
I'm unclear on your comment. Is the numbers-only script working for you or are you having problems with it? Regards, Joe

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 24 Sep 2022, 02:29

JoeWinograd wrote:
24 Sep 2022, 02:12
Hi @dadaya7852,
I'm unclear on your comment. Is the numbers-only script working for you or are you having problems with it? Regards, Joe
Previous script HorizontalVolumeSliderW10 works in games and do not switch to desktop but with numbers switching to desktop

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 24 Sep 2022, 03:42

JoeWinograd wrote:
24 Sep 2022, 02:12
Hi @dadaya7852,
I'm unclear on your comment. Is the numbers-only script working for you or are you having problems with it? Regards, Joe
Maybe HorizontalVolumeSliderW10 can be made so that the interface is not different as in VolumeAdjustNumbersOnly maybe because of different GUI on VolumeAdjustNumbersOnly causing switch to desktop

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 24 Sep 2022, 10:58

Hi @dadaya7852,
but with numbers switching to desktop
I don't know what you mean by "switching to desktop". When I run it here, it shows the numbers, then when the numbers go away, focus returns to the previously active window.
Maybe HorizontalVolumeSliderW10 can be made so that the interface is not different as in VolumeAdjustNumbersOnly
Perhaps changing the Progress command to a SplashImage command would do what you want. Try the attached script with that. If you want to change the location of the numbers (now they appear in the center of the primary monitor), you can add X and Y options to the SplashImage command, such as:
SplashImage,,B W50 X200 Y800,%Volume%,,,Arial Bold
maybe because of different GUI on VolumeAdjustNumbersOnly causing switch to desktop
Well, it's not a "different" GUI, i.e., HorizontalVolumeSliderW10 does not use a GUI at all. The original one uses the (deprecated) Progress command and the new one (attached to this post) uses the (deprecated) SplashImage command. Regards, Joe
Attachments
HorizontalVolumeSliderW10SplashImage.ahk
(862 Bytes) Downloaded 51 times

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 24 Sep 2022, 12:03

JoeWinograd wrote:
24 Sep 2022, 10:58
Hi @dadaya7852,
but with numbers switching to desktop
I don't know what you mean by "switching to desktop". When I run it here, it shows the numbers, then when the numbers go away, focus returns to the previously active window.
Maybe HorizontalVolumeSliderW10 can be made so that the interface is not different as in VolumeAdjustNumbersOnly
Perhaps changing the Progress command to a SplashImage command would do what you want. Try the attached script with that. If you want to change the location of the numbers (now they appear in the center of the primary monitor), you can add X and Y options to the SplashImage command, such as:
SplashImage,,B W50 X200 Y800,%Volume%,,,Arial Bold
maybe because of different GUI on VolumeAdjustNumbersOnly causing switch to desktop
Well, it's not a "different" GUI, i.e., HorizontalVolumeSliderW10 does not use a GUI at all. The original one uses the (deprecated) Progress command and the new one (attached to this post) uses the (deprecated) SplashImage command. Regards, Joe
Thanks a lot now games not switching to desktop but such a question feels like the numbers are not in the center of the screen

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 24 Sep 2022, 15:06

dadaya7852 wrote:Thanks a lot now games not switching to desktop
Good news!
dadaya7852 wrote:feels like the numbers are not in the center of the screen
They should be when the X and Y options are not specified. The doc says this:
Xn: Specify for n the x-coordinate of the window's upper left corner. If unspecified, the window will be horizontally centered on the screen.

Yn: Specify for n the y-coordinate of the window's upper left corner. If unspecified, the window will be vertically centered on the screen.
And that's how it works when I run it here. Regards, Joe

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 24 Sep 2022, 16:21

JoeWinograd wrote:
24 Sep 2022, 15:06
dadaya7852 wrote:Thanks a lot now games not switching to desktop
Good news!
dadaya7852 wrote:feels like the numbers are not in the center of the screen
They should be when the X and Y options are not specified. The doc says this:
Xn: Specify for n the x-coordinate of the window's upper left corner. If unspecified, the window will be horizontally centered on the screen.

Yn: Specify for n the y-coordinate of the window's upper left corner. If unspecified, the window will be vertically centered on the screen.
And that's how it works when I run it here. Regards, Joe
Thanks Joe for your help I'm sorry if I bored you how make this script without flickering thanks in advance

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 24 Sep 2022, 18:48

dadaya7852 wrote:how make this script without flickering
I don't know how to do that with the SplashImage approach. I tried Hide instead of Off, but that didn't help...it still flickered. The GUI approach does not flicker, and you have complete control over font size with it, and it avoids using the deprecated SplashImage or deprecated Progress command, so I'd recommend getting that to work. I still don't understand the "switching to desktop" problem that you're having with it, since, as I mentioned earlier, when I run it here, it shows the numbers, then when the numbers go away, focus returns to the previously active window, not to the desktop. Regards, Joe

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 25 Sep 2022, 05:06

JoeWinograd wrote:
24 Sep 2022, 18:48
dadaya7852 wrote:how make this script without flickering
I don't know how to do that with the SplashImage approach. I tried Hide instead of Off, but that didn't help...it still flickered. The GUI approach does not flicker, and you have complete control over font size with it, and it avoids using the deprecated SplashImage or deprecated Progress command, so I'd recommend getting that to work. I still don't understand the "switching to desktop" problem that you're having with it, since, as I mentioned earlier, when I run it here, it shows the numbers, then when the numbers go away, focus returns to the previously active window, not to the desktop. Regards, Joe
If i run the game in full screen and use first number script then this script just minimizes to the desktop and after that I need to open the game from taskbar

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 25 Sep 2022, 12:11

dadaya7852 wrote:If i run the game in full screen and use first number script then this script just minimizes to the desktop and after that I need to open the game from taskbar
Attached is an updated version of the GUI-based script with three improvements:

(1) Added a variable for the program to activate after the numbers go away (ActivateProgram). This should solve the main problem that you're having. I tested the script here with Firefox in a YouTube full-screen video...worked perfectly. So, change "firefox.exe" in the assignment statement to the executable for your game.

(2) Added variables for the font name, font size, and font weight of the numbers (FontName, FontSize, FontWeight) so that it's easy to experiment with (the sizes of the GUI and the numbers are calculated based on FontSize).

(3) Fixed a bug where the timer is not turned off when the numbers go away.

Regards, Joe
Attachments
VolumeAdjustNumbersOnlyV2.ahk
(1.2 KiB) Downloaded 45 times

dadaya7852
Posts: 9
Joined: 10 Aug 2022, 13:19

Re: Volume Control on PC Windows 10

Post by dadaya7852 » 26 Sep 2022, 06:15

JoeWinograd wrote:
25 Sep 2022, 12:11
dadaya7852 wrote:If i run the game in full screen and use first number script then this script just minimizes to the desktop and after that I need to open the game from taskbar
Attached is an updated version of the GUI-based script with three improvements:

(1) Added a variable for the program to activate after the numbers go away (ActivateProgram). This should solve the main problem that you're having. I tested the script here with Firefox in a YouTube full-screen video...worked perfectly. So, change "firefox.exe" in the assignment statement to the executable for your game.

(2) Added variables for the font name, font size, and font weight of the numbers (FontName, FontSize, FontWeight) so that it's easy to experiment with (the sizes of the GUI and the numbers are calculated based on FontSize).

(3) Fixed a bug where the timer is not turned off when the numbers go away.

Regards, Joe
Still https://imgur.com/a/Nrsih0P

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

Re: Volume Control on PC Windows 10

Post by JoeWinograd » 26 Sep 2022, 12:58

Hi @dadaya7852,

Two things:

(1) Post the ActivateProgram:= statement in your version of my V2 script.

(2) Run a script with this hotkey (make the hotkey whatever you want...I used Alt+Ctrl+F3):

Code: Select all

!^F3:: ;show active window title, class, process name, handle
WinGetTitle,Title,A
Handle:=WinExist("A")
WinGetClass,Class,A
WinGet,Process,ProcessName,A
WinGet,ProcessID,PID,A
ActiveWindowMetadata:="Title=" . Title . "`n`nClass=" . Class . "`n`nProcess Name=" . Process . "`n`nHandle=" . Handle . "`n`nPID=" . ProcessID
MsgBox,262208,Active Window Metadata,%ActiveWindowMetadata%
Return
Run your game and hit the hotkey. Post the resulting message box. Regards, Joe

Post Reply

Return to “Gaming Help (v1)”