Make script work only on an empty part of the taskbar Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kiwichick
Posts: 130
Joined: 21 Jan 2014, 22:03

Make script work only on an empty part of the taskbar

Post by kiwichick » 06 Aug 2022, 22:11

I have a script that allows me to control my laptop's sound volume with the mouse wheel when I hover over the taskbar (scroll for volume up/down, click to mute/unmute). Is there any way to make it work only if I hover over an empty part of the taskbar so the wheel will still work how it should for items on the taskbar?

A couple of suggestions on Reddit were:
1) See if Window Spy shows different information when hovering an app on the bar compared to empty space on the bar. I did that but there is no change at all.
2) Use a color picker to check where I'm clicking on the taskbar but, even though the taskbar looks like it's a solid colour, it isn't. It's made up of about 5 colours.

Code: Select all

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

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}

menu, tray, icon, %A_ScriptDir%\volumouse.ico
Menu, Tray, Tip, Hover taskbar and use:`nMiddle-Click or Alt to mute/unmute volume.`nScroll Up/Down to control volume.

WheelUp::
Send {Volume_Up}
return

WheelDown::
Send {Volume_Down}
return

MButton::
Send {Volume_Mute}
return

alt::
Send {Volume_Mute}
return

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

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Make script work only on an empty part of the taskbar

Post by boiler » 06 Aug 2022, 23:20

kiwichick wrote: 2) Use a color picker to check where I'm clicking on the taskbar but, even though the taskbar looks like it's a solid colour, it isn't. It's made up of about 5 colours.
Then use ImageSearch to find a segment of that repeating pattern within a few pixels of your pointer location.

Descolada
Posts: 1098
Joined: 23 Dec 2021, 02:30

Re: Make script work only on an empty part of the taskbar

Post by Descolada » 07 Aug 2022, 02:58

My attempt at it using UIA (if you need even faster speeds, then Acc should work as well):

Code: Select all

#singleinstance force
#include <UIA_Interface>
#If MouseIsOver("ahk_class Shell_TrayWnd") && OnlyTaskbarOrVolumeButton()

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}

menu, tray, icon, %A_ScriptDir%\volumouse.ico
Menu, Tray, Tip, Hover taskbar and use:`nMiddle-Click or Alt to mute/unmute volume.`nScroll Up/Down to control volume.

WheelUp::
Send {Volume_Up}
return

WheelDown::
Send {Volume_Down}
return

MButton::
Send {Volume_Mute}
return

alt::
Send {Volume_Mute}
return

OnlyTaskbarOrVolumeButton() {
    pt := UIA_Interface().ElementFromPoint(,,False)
    try return (ctrlType := pt.CurrentControlType) == 50033 ; Pane element
    	|| ctrlType == 50021 ; or TaskBar element
    	|| pt.CurrentAutomationId == "{7820AE73-23E3-4229-82C1-E41CB67D5B9C}" ; or Windows 10 Volume button (I'm not sure if the id is the same in other computers though)
    	|| InStr(pt.CurrentName, "Volume") ; or Windows 11 volume button
}

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

kiwichick
Posts: 130
Joined: 21 Jan 2014, 22:03

Re: Make script work only on an empty part of the taskbar

Post by kiwichick » 07 Aug 2022, 03:56

Descolada wrote:
07 Aug 2022, 02:58
My attempt at it using UIA (if you need even faster speeds, then Acc should work as well):

Code: Select all

#singleinstance force
#include <UIA_Interface>
#If MouseIsOver("ahk_class Shell_TrayWnd") && OnlyTaskbarOrVolumeButton()

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"
   ExitApp
}

menu, tray, icon, %A_ScriptDir%\volumouse.ico
Menu, Tray, Tip, Hover taskbar and use:`nMiddle-Click or Alt to mute/unmute volume.`nScroll Up/Down to control volume.

WheelUp::
Send {Volume_Up}
return

WheelDown::
Send {Volume_Down}
return

MButton::
Send {Volume_Mute}
return

alt::
Send {Volume_Mute}
return

OnlyTaskbarOrVolumeButton() {
    pt := UIA_Interface().ElementFromPoint(,,False)
    try return (ctrlType := pt.CurrentControlType) == 50033 ; Pane element
    	|| ctrlType == 50021 ; or TaskBar element
    	|| pt.CurrentAutomationId == "{7820AE73-23E3-4229-82C1-E41CB67D5B9C}" ; or Windows 10 Volume button (I'm not sure if the id is the same in other computers though)
    	|| InStr(pt.CurrentName, "Volume") ; or Windows 11 volume button
}

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}
Thanks for your contribution. I'm not entirely sure what you meant it to do but it doesn't do what I'd like. My original script worked over the entire taskbar including icons in the notification area (in red rectangle). Yours doesn't work over icons in the notification area but works across the rest of the taskbar even if I'm over icons of open or pinned items (in green rectangle). I don't want it to work over those items. The other way around would be better (ie: it works over the notification area and nowhere else).
2022-08-07_205014.png
2022-08-07_205014.png (26.57 KiB) Viewed 1082 times

kiwichick
Posts: 130
Joined: 21 Jan 2014, 22:03

Re: Make script work only on an empty part of the taskbar

Post by kiwichick » 07 Aug 2022, 04:04

boiler wrote:
06 Aug 2022, 23:20
Then use ImageSearch to find a segment of that repeating pattern within a few pixels of your pointer location.
Thank you but, sorry, I don't really know what repeating pattern I would be searching for (see screenshot) or what I would do with it in regards to my script. I'm not even sure why I would do an image search for it seeing as I can just take a screenshot of it.
empty taskbar.png
empty taskbar.png (7.13 KiB) Viewed 1070 times

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Make script work only on an empty part of the taskbar

Post by boiler » 07 Aug 2022, 04:49

kiwichick wrote: Thank you but, sorry, I don't really know what repeating pattern I would be searching for (see screenshot) or what I would do with it in regards to my script.
You said you couldn’t check for any one color for being under the mouse to indicate your mouse is over an empty part of the taskbar because it is made up of 5 colors. If the pixels making up those 5 colors are some kind of consistent pattern, then you could use ImageSearch to see if that pattern is found in the area under the mouse location to let you know the mouse is over an empty part of the taskbar.

kiwichick wrote: I'm not even sure why I would do an image search for it seeing as I can just take a screenshot of it.
empty taskbar.png
That’s not what ImageSearch does. It is not a mechanism for capturing part of the screen. It’s for finding a reference image on the screen. Searching for what has previously been captured as an empty part of the taskbar (not the whole thing, but just a small piece of it) in the area under the mouse position would let you know if the mouse is over an empty part of the taskbar.

This is actually a pretty easy solution to your problem, so don’t dismiss it because you don’t understand how it would work yet.

kiwichick
Posts: 130
Joined: 21 Jan 2014, 22:03

Re: Make script work only on an empty part of the taskbar

Post by kiwichick » 07 Aug 2022, 16:49

boiler wrote:
07 Aug 2022, 04:49
use ImageSearch to see if that pattern is found in the area under the mouse location
I don't how to do that.
boiler wrote:
07 Aug 2022, 04:49
This is actually a pretty easy solution to your problem, so don’t dismiss it because you don’t understand how it would work yet.
I'm definitely not dismissing it, I'm open to any solutions to my problem and am grateful for your help. I just don't have a clue how to use ImageSearch or incorporate it into my script.

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Make script work only on an empty part of the taskbar

Post by Xtra » 07 Aug 2022, 17:30

The other way around would be better (ie: it works over the notification area and nowhere else)
Try:

Code: Select all

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win, Ctrl
    return (WinExist(WinTitle . " ahk_id " . Win) && Ctrl = "ToolbarWindow321")
}

kiwichick
Posts: 130
Joined: 21 Jan 2014, 22:03

Re: Make script work only on an empty part of the taskbar  Topic is solved

Post by kiwichick » 07 Aug 2022, 17:46

Xtra wrote:
07 Aug 2022, 17:30
The other way around would be better (ie: it works over the notification area and nowhere else)
Try:

Code: Select all

MouseIsOver(WinTitle) {
    MouseGetPos,,, Win, Ctrl
    return (WinExist(WinTitle . " ahk_id " . Win) && Ctrl = "ToolbarWindow321")
}
Thanks but I've just discovered an app I'm currently using (7+ Taskbar Tweaker) does exactly what I want.

Post Reply

Return to “Ask for Help (v1)”