Page 1 of 1

Automatic Scroll Wheel Speaker Volume Control When Hovering Over the Taskbar

Posted: 21 Sep 2019, 14:39
by jackdunning
This short tip comes directly from the AutoHotkey documentation for the #If directive. I republish it here for those who haven't had a chance to read all the online documentation. Plus, a while back I added it to my main AutoHotkey script and now use my mouse scroll wheel hovering over the Windows Taskbar as my primary method for controlling speaker volume.


A number of other scripts of this type have appeared in the forum, but I have found none quite so simple and easy-to-use.

The #IfWinActive directive restricts Hotkeys to particular active program windows. However, you'll find many times when expressions prove useful for determining whether or not to activate a Hotkey. As in this example, the Hotkey works only when the mouse cursor hovers over the Taskbar. The following script does this by implementing an #If expression directive which checks the mouse cursor location:

Code: Select all

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

{  MouseGetPos,,, Win
   Return WinExist(WinTitle . " ahk_id " . Win)
I discuss this code (and other examples of mouse cursor location-sensitive AutoHotkey applications) in Chapter Six of the book AutoHotkey Hotkeys: Tips, Tricks, Techniques, and Best Practices.