Adding functionality to known taskbar-volume-scrolling script

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

Adding functionality to known taskbar-volume-scrolling script

Post by a0l0e0x000 » 17 Nov 2022, 17:54

Seen the cool script in AHK documentation that allows you to scroll on taskbar to change volume? Here it is:

Code: Select all

#If MouseIsOver("ahk_class Shell_TrayWnd")
WheelUp::Send {Volume_Up}
WheelDown::Send {Volume_Down}

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}
Now lets add my "Hold right click to scroll faster" functionality working at the same time
This is a bit of a complex one so I won't explain it in detail and the code is a bit ugly with no comments, as I don't have time to polish it...

...so here are the functionalities it brings:

- hold right mouse button any time while scrolling to scroll faster
- scroll on taskbar to change volume (added functionality makes adjustments finer when volume is low)
- scroll on taskbar while holding right mouse button to change volume quicker (added functionality makes adjustments finer when volume is low)
... honestly just run it and test it out


How to run:
Here are the 4 scripts you need to have in the same folder. *** ALSO: RENAME SCRIPT 2, 3 AND 4 ACCORDINGLY AS THEY ARE CALLED FROM SCRIPT 1
Only run the 1st script
(it is required because the other 3 scripts need to be run in the correct sequence to work properly for some reason related to overriding hotkeys...)
(feel free to adjust the numbers to your liking)

Code: Select all

; Scrolls have to be run in order 1, 2, 3 to work

SetWorkingDir %A_ScriptDir%

Run, Scroll 1of3 RButtonFastScroll.ahk
sleep, 1000
Run, Scroll 2of3 TaskbarVolScroll.ahk
sleep, 1000
Run, Scroll 3of3 TaskbarFastVolScroll.ahk
return
Scroll 1of3 RButtonFastScroll.ahk

Code: Select all

#singleinstance, force
#If not MouseIsOver("ahk_class Shell_TrayWnd")
RButton::
if MouseIsOver("ahk_class Shell_TrayWnd") = false {
FastScroll := 0
hotkey, Wheelup , FastScrollUp, on
hotkey, Wheeldown , FastScrollDown, on
keywait, RButton
hotkey, Wheelup , FastScrollUp, off
hotkey, Wheeldown , FastScrollDown, off
if (FastScroll = 0)
{
send, {RButton}
}
return
}
else {   ;REDUNDANT - WILL NEVER HAPPEN DUE TO #IF - IS COPPIED IN ANOTHER SCRIPT
VolumeScroll := 0
hotkey, Wheelup , VolumeScrollUp, on
hotkey, Wheeldown , VolumeScrollDown, on
keywait, RButton
hotkey, Wheelup , VolumeScrollUp, off
hotkey, Wheeldown , VolumeScrollDown, off
if (VolumeScroll = 0)
{
send, {RButton}
}
return
}

FastScrollUp:
send, {wheelup 4}
if (FastScroll = 0)
{
FastScroll := 1
}
return

FastScrollDown:
send, {wheeldown 4}
if (FastScroll = 0)
{
FastScroll := 1
}
return

VolumeScrollUp: ;REDUNDANT - WILL NEVER HAPPEN DUE TO #IF - IS COPPIED IN ANOTHER SCRIPT
soundget, vol
	if (vol>10) {
	SoundSet, +10
	}
	else {
	SoundSet, +2
	}
if (VolumeScroll = 0)
{
VolumeScroll := 1
}
return

VolumeScrollDown: ;REDUNDANT - WILL NEVER HAPPEN DUE TO #IF - IS COPPIED IN ANOTHER SCRIPT
soundget, vol
	if (vol>25) {
	SoundSet, -10
	}
	else {
	SoundSet, -2
	}
if (VolumeScroll = 0)
{
VolumeScroll := 1
}
return

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}
Scroll 2of3 TaskbarVolScroll.ahk

Code: Select all

#singleinstance, force
#If MouseIsOver("ahk_class Shell_TrayWnd")
WheelUp::
soundget, vol
if (vol>10) {
SoundSet, +3
}
else {
SoundSet, +1
}
return

WheelDown::
soundget, vol
if (vol>10) {
SoundSet, -3
}
else {
SoundSet, -1
}
return

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}
Scroll 3of3 TaskbarFastVolScroll.ahk

Code: Select all

#singleinstance, force
#If MouseIsOver("ahk_class Shell_TrayWnd")

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}


RButton::
if MouseIsOver("ahk_class Shell_TrayWnd") = false { ;REDUNDANT - WILL NEVER HAPPEN DUE TO #IF - IS COPPIED IN ANOTHER SCRIPT
FastScroll := 0
hotkey, Wheelup , FastScrollUp, on
hotkey, Wheeldown , FastScrollDown, on
keywait, RButton
hotkey, Wheelup , FastScrollUp, off
hotkey, Wheeldown , FastScrollDown, off
if (FastScroll = 0)
{
send, {RButton}
}
return
}
else {
VolumeScroll := 0
hotkey, Wheelup , VolumeScrollUp, on
hotkey, Wheeldown , VolumeScrollDown, on
keywait, RButton
hotkey, Wheelup , VolumeScrollUp, off
hotkey, Wheeldown , VolumeScrollDown, off
if (VolumeScroll = 0)
{
send, {RButton}
}
return
}

FastScrollUp: ;REDUNDANT - WILL NEVER HAPPEN DUE TO #IF - IS COPPIED IN ANOTHER SCRIPT
send, {wheelup 4}
if (FastScroll = 0)
{
FastScroll := 1
}
return

FastScrollDown: ;REDUNDANT - WILL NEVER HAPPEN DUE TO #IF - IS COPPIED IN ANOTHER SCRIPT
send, {wheeldown 4}
if (FastScroll = 0)
{
FastScroll := 1
}
return

VolumeScrollUp:
soundget, vol
	if (vol>10) {
	SoundSet, +10
	}
	else {
	SoundSet, +2
	}
if (VolumeScroll = 0)
{
VolumeScroll := 1
}
return

VolumeScrollDown:
soundget, vol
	if (vol>25) {
	SoundSet, -10
	}
	else {
	SoundSet, -2
	}
if (VolumeScroll = 0)
{
VolumeScroll := 1
}
return

Return to “Scripts and Functions (v1)”