Volume Control on PC Windows 10
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
Hi Dave,
It's not a good idea to store files on your desktop. You should have a foldering scheme with an organizational structure that takes advantage of the Windows file system (folders and subfolders with your files organized in a structure that makes sense for you). That said, for now, since your AutoHotkey file is on the desktop, simply right-click on it there (that is, on the desktop...forget about using File Explorer) and select Create shortcut. That will put the shortcut on the desktop, too. That should end your frustration. Regards, Joe
It's not a good idea to store files on your desktop. You should have a foldering scheme with an organizational structure that takes advantage of the Windows file system (folders and subfolders with your files organized in a structure that makes sense for you). That said, for now, since your AutoHotkey file is on the desktop, simply right-click on it there (that is, on the desktop...forget about using File Explorer) and select Create shortcut. That will put the shortcut on the desktop, too. That should end your frustration. Regards, Joe
-
- Posts: 16
- Joined: 21 Apr 2018, 18:16
- Contact:
Re: Volume Control on PC Windows 10
Still cannot find the file, Volume.ahk anywhere within my File Explorer. Therefore, I cannot create a shortcut to the file, Volume.ahk to place into my Start Up Folder. I'm thinking, what if I were to save my Volume (.ahk) file as a .txt file Volume.txt, then create a shortcut for the Volume.txt file. Copy that file, & Paste it into my Startup Folder. Would that work? Upon every Start Up my Volume AutoHot Key would be activated without me needing to double clicking on the Volume AutoHot key (which is on my desktop) to prompt Horizontal Volume Slider W10, which I been needing to do per each PC Start Up & wish to have Volume AutoHot key automatically activated each PC Start Up.
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
Dave,
You said in a previous post that the Volume.ahk file is located on your desktop. So there's no need for using File Explorer. Simply right-click the Volume.ahk file on your desktop and select Create shortcut. That will put the shortcut on the desktop, too. Then copy (or move) the shortcut to your Startup folder. Regards, Joe
You said in a previous post that the Volume.ahk file is located on your desktop. So there's no need for using File Explorer. Simply right-click the Volume.ahk file on your desktop and select Create shortcut. That will put the shortcut on the desktop, too. Then copy (or move) the shortcut to your Startup folder. Regards, Joe
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Volume Control on PC Windows 10
Hey Joe.JoeWinograd wrote:......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 TrayIconFile:=A_WinDir . "\System32\DDORes.dll" ; get tray icon from DDORes.dll TrayIconNum:="-2032" ; use headphones as tray icon (icon 2032 in DDORes) Menu,Tray,Tip,%TrayTip% Menu,Tray,Icon,%TrayIconFile%,%TrayIconNum% 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
Cool stuff. Long time I have used Volume On-Screen-Display (OSD) -- by Rajat to find in AHK-Tutorial under Script Showcase.
Unfortunately, official example has two bars and my heavy trys to eliminate one of them wasn`t succesfull at all.
The official example had a very strange code. Much too strange for me.
Your tiny script seems very easy to modify. I think my next OSD-Volume control will have your code as framework.
Thanks for sharing.
Einfach nur ein toller Typ.
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
You're welcome, divanebaba, happy to share. Your OSD Volume Control is very interesting...looking forward to seeing it. Cheers, Joe
-
- Posts: 16
- Joined: 21 Apr 2018, 18:16
- Contact:
Re: Volume Control on PC Windows 10
Working like a charm, Joe. Cannot thank you enough!
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
You're very welcome, Dave. I'm really glad to hear that. Thanks for letting me know. Regards, Joe
Re: Volume Control on PC Windows 10
Just in case someone looks for AHK v.2 version of a volume control code. This one uses system maintenance of Volume keys, but you can simply adjust it to increase/decrease volume in your selected granularity, just by using for example SoundSet("+1") or SoundSet("-1") (for granularity 1) instead of the Send "{Volume_Up}" and Send "{Volume_down}" commands.
If you just need a volume control shortcuts, you probably already have some OSD on system, which is displayed on volume change. In this situation this simple code will be enough for you (AHK v.2):
But if you need your own OSD, then in this is a working code for current AHK v.2:
If you just need a volume control shortcuts, you probably already have some OSD on system, which is displayed on volume change. In this situation this simple code will be enough for you (AHK v.2):
Code: Select all
#SingleInstance force
TraySetIcon(A_WinDir "\System32\DDORes.dll", -2032) ; use headphones as tray icon (icon 2032 in DDORes)
A_IconTip := "Press Win + Ctrl + Up/Down to adjust the volume."
^#Up::Send "{Volume_Up}"
^#Down::Send "{Volume_Down}"
Code: Select all
#SingleInstance force
TraySetIcon(A_WinDir "\System32\DDORes.dll", -2032) ; use headphones as tray icon (icon 2032 in DDORes)
A_IconTip := "Press Win + Ctrl + Up/Down to adjust the volume."
DisplaySlider()
return
^#Up::
Send "{Volume_Up}"
DisplaySlider()
Return
^#Down::
Send "{Volume_Down}"
DisplaySlider()
Return
DisplaySlider() {
volume := SoundGet()
Gui := GuiCreate("+AlwaysOnTop -Caption +ToolWindow") ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui.Add("Progress", "w300 h20 cBlue", volume)
Gui.Show("NoActivate") ; NoActivate avoids deactivating the currently active window.
SetTimer(Func("SliderOff").bind(Gui), -1000)
}
SliderOff(Gui) {
Gui.Destroy()
}
-
- Posts: 10
- Joined: 28 Oct 2017, 13:19
Re: Volume Control on PC Windows 10
JoeWinograd wrote: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 TrayIconFile:=A_WinDir . "\System32\DDORes.dll" ; get tray icon from DDORes.dll TrayIconNum:="-2032" ; use headphones as tray icon (icon 2032 in DDORes) Menu,Tray,Tip,%TrayTip% Menu,Tray,Icon,%TrayIconFile%,%TrayIconNum% 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
Thanks so much Joe!
I am trying to play with the sizing and doing research on "progress" so I tried something like this
Code: Select all
Progress,w800,%Volume%,%Volume%,Volume,HorizontalVolumeSliderW10
If anyone could maybe help me on where I am messing up with the "w800" I would appreciate it so so much
Travis
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
Hi Travis,
It's easier to control a progress bar in a GUI, so I rewrote the Progress command into a GUI Progress control (it's also good preparation for V2, which has removed the Progress command). I put four variables near the top of the script that allow you to specify the bar's width, height, and color, as well as the number of milliseconds to leave it on the screen, ready for the Alt+LeftArrow and Alt+RightArrow. Here's the new script:
It works perfectly here with AHK v1.1.30.00 U32 in W10 64-bit V1803 (Build 17134.228), but if you have any problems, let me know. Regards, Joe
It's easier to control a progress bar in a GUI, so I rewrote the Progress command into a GUI Progress control (it's also good preparation for V2, which has removed the Progress command). I put four variables near the top of the script that allow you to specify the bar's width, height, and color, as well as the number of milliseconds to leave it on the screen, ready for the Alt+LeftArrow and Alt+RightArrow. Here's the new script:
Code: Select all
; Joe Winograd, 26-Aug-2018
#Warn,UseUnsetLocal
#NoEnv
#SingleInstance force
SetBatchLines,-1
; change these three value to whatever you want
BarWidth:=800
BarHeight:=20
BarColor:="Blue"
BarMillisecondsToStayOnScreen:=3000 ; 3 seconds
ProgramName:=A_ScriptName
StringTrimRight,ProgramName,ProgramName,4 ; remove .ahk or .exe
SoundGet,Volume
Volume:=Round(Volume)
TrayTip:="Alt+LeftArrow or Alt+RightArrow to adjust volume" . "`nCurrent Volume=" . Volume
TrayIconFile:=A_WinDir . "\System32\DDORes.dll" ; get tray icon from DDORes.dll
TrayIconNum:="-2032" ; use headphones as tray icon (icon 2032 in DDORes)
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
!Left::
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,-1
Gosub,DisplaySlider
Return
!Right::
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,+1
Gosub,DisplaySlider
Return
SliderOff:
Gui,Hide
Return
DisplaySlider:
SoundGet,Volume
Volume:=Round(Volume)
Title:=ProgramName . " Current Volume=" . Volume
Gui,Show,,%Title%
GuiControl,,BarVal,%Volume%
TrayTip:="Alt+LeftArrow or Alt+RightArrow to adjust volume" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return
-
- Posts: 10
- Joined: 28 Oct 2017, 13:19
Re: Volume Control on PC Windows 10
Joe!!! you are the man! Thank you so much!
I read about Gui while learning about "progress" in ahk but didn't delve into it too much, the past hour I did just that so thank you!
I hope you don't mind but just wanted to add 2 small customizations.
(use notepad++ to past Joe's code because it shows the line numbers unlike normal notepad, obv Joe knows this )
1) on line 12 and line 52 for the Y position on the screen which allows someone to set the Y position on their screen. Just change line 12 where it says "Ypos::"Y800" and just change the number to what is appropriate for your screen, remember 0 position is at the top not the bottom.
It's cool because if you're watching a movie and don't want the bar in the way of the movie on the screen while you're watching
2) on line 40 where it says
this just makes the asterix/multiplication sign on the number pad toggle mute/unmute
3) this code uses the Numberpad keys on the right of the keyboard (which I never use, but if you do then just use Joe's Alt left/right arrow code)
-------------------------------------------
I read about Gui while learning about "progress" in ahk but didn't delve into it too much, the past hour I did just that so thank you!
I hope you don't mind but just wanted to add 2 small customizations.
(use notepad++ to past Joe's code because it shows the line numbers unlike normal notepad, obv Joe knows this )
1) on line 12 and line 52 for the Y position on the screen which allows someone to set the Y position on their screen. Just change line 12 where it says "Ypos::"Y800" and just change the number to what is appropriate for your screen, remember 0 position is at the top not the bottom.
It's cool because if you're watching a movie and don't want the bar in the way of the movie on the screen while you're watching
2) on line 40 where it says
Code: Select all
NumpadMult::
Send {Volume_Mute}
Return
3) this code uses the Numberpad keys on the right of the keyboard (which I never use, but if you do then just use Joe's Alt left/right arrow code)
-------------------------------------------
Code: Select all
; Joe Winograd, 26-Aug-2018
#Warn,UseUnsetLocal
#NoEnv
#SingleInstance force
SetBatchLines,-1
; change these three value to whatever you want
BarWidth:=1300
BarHeight:=50
BarColor:="Green"
BarMillisecondsToStayOnScreen:=1000 ; 3 seconds
Ypos:="Y800" ; bar distance from top of the screen, commenting this line out with ";" makes it centered
ProgramName:=A_ScriptName
StringTrimRight,ProgramName,ProgramName,4 ; remove .ahk or .exe
SoundGet,Volume
Volume:=Round(Volume)
TrayTip:="Numpad Subtract or Numbpad Add to adjust volume" . "`nCurrent Volume=" . Volume
TrayIconFile:=A_WinDir . "\System32\DDORes.dll" ; get tray icon from DDORes.dll
TrayIconNum:="-2032" ; use headphones as tray icon (icon 2032 in DDORes)
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
NumpadSub::
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,-10
Gosub,DisplaySlider
Return
NumpadAdd::
SetTimer,SliderOff,%BarMillisecondsToStayOnScreen%
SoundSet,+10
Gosub,DisplaySlider
Return
NumpadMult::
Send {Volume_Mute}
Return
SliderOff:
Gui,Hide
Return
DisplaySlider:
SoundGet,Volume
Volume:=Round(Volume)
Title:=ProgramName . " Current Volume=" . Volume
Gui,Show,%Ypos%,%Title%
GuiControl,,BarVal,%Volume%
TrayTip:="Numpad Subtract or Numbpad Add to adjust volume" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
You're very welcome, Travis, I'm glad that it works for you...and that you were able to customize it to meet your needs. Regards, Joe
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
Hi Travis,
Your idea inspired me to improve the script. I added five additional variables, the names of which should make it obvious what they do:
BarXlocation
BarYlocation
HotkeyVolumeDown
HotkeyVolumeUp
VolumeIncrement
The first two include the "x" and "y" in the string, and I changed BarWidth and BarHeight to include the "w" and "h" in the string. The HotkeyVolumeDown and HotkeyVolumeUp are specified in standard AHK hotkey notation. The new script below has my "!Left" and "!Right" commented out, with your "NumpadSub" and "NumpadAdd" active, but, of course, the beauty of the new script is that users can easily set whatever hotkeys they want to use. Also, the new script has my volume increment of 1 commented out and your volume increment of 10 active. Btw, I changed the tray icon to the music note from shell32.dll. Regards, Joe
Your idea inspired me to improve the script. I added five additional variables, the names of which should make it obvious what they do:
BarXlocation
BarYlocation
HotkeyVolumeDown
HotkeyVolumeUp
VolumeIncrement
The first two include the "x" and "y" in the string, and I changed BarWidth and BarHeight to include the "w" and "h" in the string. The HotkeyVolumeDown and HotkeyVolumeUp are specified in standard AHK hotkey notation. The new script below has my "!Left" and "!Right" commented out, with your "NumpadSub" and "NumpadAdd" active, but, of course, the beauty of the new script is that users can easily set whatever hotkeys they want to use. Also, the new script has my volume increment of 1 commented out and your volume increment of 10 active. Btw, I changed the tray icon to the music note from shell32.dll. Regards, Joe
Code: Select all
; Joe Winograd, 27-Aug-2018
; Developed for Windows 10, but tested successfully on W7, W8.1, and W10 (all 64-bit)
#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"
HotkeyVolumeDown:="NumpadSub"
HotkeyVolumeUp:="NumpadAdd"
;VolumeIncrement:=1
VolumeIncrement:=10
; end values to change
ProgramName:=A_ScriptName
StringTrimRight,ProgramName,ProgramName,4 ; remove .ahk or .exe
Hotkey,%HotkeyVolumeDown%,VolumeDown
Hotkey,%HotkeyVolumeUp%,VolumeUp
SoundGet,Volume
Volume:=Round(Volume)
TrayTip:=HotkeyVolumeDown . " or " . HotkeyVolumeUp . " to adjust volume" . "`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
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" . "`nCurrent Volume=" . Volume
Menu,Tray,Tip,%TrayTip%
Return
Last edited by JoeWinograd on 05 Jun 2019, 11:27, edited 2 times in total.
-
- Posts: 10
- Joined: 28 Oct 2017, 13:19
Re: Volume Control on PC Windows 10
short post
/bow
ty joe, love the icon change also
/bow
ty joe, love the icon change also
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
-
- Posts: 10
- Joined: 28 Oct 2017, 13:19
Re: Volume Control on PC Windows 10
paying homage
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
Ah, that kind of "bow". Thanks!
Re: Volume Control on PC Windows 10
Thanks, Joe, your solution worked perfectly
- JoeWinograd
- Posts: 2185
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Volume Control on PC Windows 10
You're welcome, Ray, I'm very glad to hear that. Thanks for joining the group today and letting me know. Regards, Joe
Re: Volume Control on PC Windows 10
To get the vertical volume slider you can use Sendinput {Volume_Up} and Sendinput {Volume_Down} instead of the SoundSet command. If you only need to use these when certain windows are open, you can combine with the If WinExist command.
For example, I generally prefer my Function keys to work as function keys rather than media keys - except when I have Youtube TV open (the yTV windows' names always seem to start with "Watching"). My "volume up" setup is as follows (I like to define the function separately in case I want to assign it to different keys and change it in one place in the future):[Mod edit: [code][/code] tags added.]
For example, I generally prefer my Function keys to work as function keys rather than media keys - except when I have Youtube TV open (the yTV windows' names always seem to start with "Watching"). My "volume up" setup is as follows (I like to define the function separately in case I want to assign it to different keys and change it in one place in the future):
Code: Select all
If_yTV_volumeUp()
{
If WinExist ("Watching")
Sendinput {Volume_Up 1}
return
}
F3::If_yTV_volumeUp()
JoeWinograd wrote: ↑23 Apr 2018, 11:04Hi David,
While swagfag's script will work, the problem is that the Left and Right arrow keys will always control the volume. In other words, you'll lose the use of the Left and Right arrow keys for their normal purpose in all programs. This is really untenable. If you're going to use that script, I suggest having a modifier key along with the Left and Right arrows, perhaps Alt or Ctrl or Shift, or maybe even two modifier keys, such as Alt+Ctrl or Ctrl+Shift. In AutoHotkey, here are the codes for the modifier keys:
Alt is !
Ctrl is ^
Shift is +
Win is # (that's the Windows logo key)
So, for example, the revised code using, say, Ctrl+Shift is:
However, this is not going to give you the W10 horizontal slider. It will, indeed, increase/decrease the volume by 5% each time, but you won't see the slider. I'm not aware of any way to expose the W10 horizontal volume slider programmatically. You can expose the W10 vertical volume slider programmatically via the SndVol.exe command line (which could easily be called in an AutoHotkey script via the Run command), but not the horizontal one.Code: Select all
^+Left::SoundSet,-5 ^+Right::SoundSet,+5
Since you're new to AutoHotkey, you may find my article helpful:
AutoHotkey - Getting Started
After that, I suggest tidbit's excellent tutorial at this site:
AutoHotkey Beginner Tutorial
Re controlling sound with AHK scripts, you may find another one of my articles to be helpful:
How to create an on/off toggle to mute the system audio/sound with a single mouse click or single keystroke
It would be very easy to modify the Mute/Unmute feature in that script to a VolumeUp/VolumeDown feature.
Welcome to the wonderful world of AutoHotkey! Regards, Joe