Right-click and scroll to control volume

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
XMCQCX
Posts: 231
Joined: 14 Oct 2020, 23:44

Right-click and scroll to control volume

Post by XMCQCX » 04 Feb 2023, 15:27

Hi,
This is the script I'm using the most. The two main issues when using right-click as modifier is the right click might lose some functionalities and context menus popping up. A workaround is to send ESC to close them. The only issue with the script below is that sending ESC is exiting full screen. Can "RButton Up" be "ignored" when the GUI exist to prevent sending ESC ? Is that something I can do to prevent this ? I would really appreciate the help, thanks.
Tested on Windows 10.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
A_MaxHotkeysPerInterval := 150

DDLPath := "C:\Windows\System32\sndvolsso.dll"

GuiVol := Gui()
hGuiVol := GuiVol.Hwnd
GuiVol.Opt("-Caption +Border +ToolWindow")
GuiVol.SetFont("s12")
GuiVol.BackColor := "101010"
GuiVol.Add("Text", "w300 Cwhite Center", "Volume")
picGuiVol := GuiVol.Add("Picture",, DDLPath)
progGuiVol := GuiVol.Add("Progress", "x+m yp+8 h20 w225 c0078D7")
textGuiVol := GuiVol.Add("Text", "x+m w25 Cwhite Center")

~RButton & WheelUp::
~RButton & WheelDown::
{
	static prevVol := 0
    SoundSetVolume Instr(A_ThisHotkey, "WheelDown") ? "-2" : "+2"
	strGetVol := SoundGetVolume()
	progGuiVol.Value := strGetVol
    textGuiVol.Value := Round(strGetVol)

	if (strGetVol = 0 && prevVol != "NoSound")
		picGuiVol.Value := "*Icon3 " DDLPath, prevVol := "NoSound"

	else if (strGetVol >=1 && strGetVol<=32) && (prevVol != "Low")
		picGuiVol.Value := "*Icon4 " DDLPath, prevVol := "Low"

	else if (strGetVol >=33 && strGetVol<=65) && (prevVol != "Medium")
		picGuiVol.Value := "*Icon5 " DDLPath, prevVol := "Medium"

	else if (strGetVol >=66 && strGetVol<=100) && (prevVol != "High")
		picGuiVol.Value := "*Icon6 " DDLPath, prevVol := "High"

	GuiVol.Show("NoActivate")
    ;~ GuiVol.Show("x" (A_ScreenWidth-430) "y" (A_ScreenHeight-150) " NoActivate")

	WinSetAlwaysOnTop(1, "ahk_id " hGuiVol)
    WinSetTransparent "225", "ahk_id " hGuiVol
	SetTimer () => GuiVol.Hide(), "-1500"
}

#HotIf WinExist("ahk_id " hGuiVol)
	RButton Up::
    {
		activeWin := WinGetProcessName("A")
		Switch activeWin
		{
			Case "chrome.exe": Sleep 10
			Case "msedge.exe": Sleep 40
		}
		Send "{Esc}"
	}
#HotIf
Last edited by XMCQCX on 04 Feb 2023, 15:44, edited 1 time in total.

DustinLuck
Posts: 7
Joined: 28 Jul 2021, 12:26

Re: Right-click and scroll to control volume

Post by DustinLuck » 04 Feb 2023, 15:41

Get rid of the tildes (~) in front of your hotkey definitions. This will stop the context menu from popping up when you use them. As a side effect, it will also disable the RButton, but you can make it work independently by adding a hotkey for RButton that remaps it to RButton.

Code: Select all

RButton::RButton

XMCQCX
Posts: 231
Joined: 14 Oct 2020, 23:44

Re: Right-click and scroll to control volume

Post by XMCQCX » 04 Feb 2023, 16:54

DustinLuck wrote:
04 Feb 2023, 15:41
Thanks for the suggestion. But it's disabling right-click drag.
Last edited by XMCQCX on 04 Feb 2023, 18:06, edited 1 time in total.

DustinLuck
Posts: 7
Joined: 28 Jul 2021, 12:26

Re: Right-click and scroll to control volume

Post by DustinLuck » 04 Feb 2023, 17:22

it's disabling right-click drag
Right you are. I hadn't tested that. To preserve dragging behavior while holding down the right mouse button, you need to handle the down and up separately.

Code: Select all

~RButton::Send {RButton Down}
RButton Up::Send {RButton Up}

User avatar
mikeyww
Posts: 26971
Joined: 09 Sep 2014, 18:38

Re: Right-click and scroll to control volume

Post by mikeyww » 04 Feb 2023, 17:39

An option:

Code: Select all

#Requires AutoHotkey v1.1.33
#If GetKeyState("RButton", "P")
WheelDown::
SoundBeep 1500
Return
#If

Post Reply

Return to “Ask for Help (v2)”