Closing Programs/ Windows by a Middle-click on the Taskbar

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Closing Programs/ Windows by a Middle-click on the Taskbar

Post by Alexander2 » 01 Jul 2022, 12:56

Does anyone know what commands can be used to close a program/ window by middle-clicking on its icon in the taskbar?
(Previously, I used the application Taskbar Tweaker to close programs by middle-clicking on their icons in the taskbar. But since Taskbar Tweaker does not work in Windows 11, I am seeking an alternative. Perhaps it is possible to write an AutoHotkey script.)
untittled.png
untittled.png (8.91 KiB) Viewed 1378 times

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

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by mikeyww » 01 Jul 2022, 13:10

I have my taskbar at the top edge. You can adjust as needed.

Code: Select all

SysGet, mwa, MonitorWorkArea

#If mousePos("y") < mwaTop
MButton::
Click, R
Sleep, 300
Send {Up}`n
Return
#If

mousePos(xy) {
 CoordMode, Mouse
 MouseGetPos, xpos, ypos
 Return xy = "y" ? ypos : xpos
}

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by Alexander2 » 01 Jul 2022, 14:02

mikeyww wrote:
01 Jul 2022, 13:10
I have my taskbar at the top edge. You can adjust as needed.

Code: Select all

SysGet, mwa, MonitorWorkArea

#If mousePos("y") < mwaTop
MButton::
Click, R
Sleep, 300
Send {Up}`n
Return
#If

mousePos(xy) {
 CoordMode, Mouse
 MouseGetPos, xpos, ypos
 Return xy = "y" ? ypos : xpos
}
Thank you.
If I want to put this script within a file with many other scripts, should the line SysGet, mwa, MonitorWorkArea be put immediately before this script or at the very beginning of the file, before all the other scripts within the file?
I have tried running the script but do not understand what needs to be changed in it so that it may close programs/ windows when I middle-click on their taskbar icons.

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

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by mikeyww » 01 Jul 2022, 14:15

Top of script. The file is the script.

Could try:

Code: Select all

#If mouseOutside()
MButton::
Click, R
Sleep, 300
Send {Up}`n
Return
#If

mouseOutside() {
 SysGet, mwa, MonitorWorkArea
 CoordMode, Mouse
 MouseGetPos, x, y
 Return x < mwaLeft || x > mwaRight || y < mwaTop || y > mwaBottom
}
Or:

Code: Select all

#If mouseOverTaskbar()
MButton::
Click, R
Sleep, 300
Send {Up}`n
Return
#If

mouseOverTaskbar() {
 CoordMode, Mouse
 WinGetPos, x, y, w, h, ahk_class Shell_TrayWnd
 MouseGetPos, mx, my
 Return mx >= x && mx < x + w && my >= y && my < y + h
}

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by Alexander2 » 02 Jul 2022, 11:08

Thank you for the scripts. Now I understand what the scripts do. They open the context menu by right-clicking on an icon and then send the Up arrow keystroke in order to select the Close command in the context window.
Is it impossible to retrieve the name of a window/ program by clicking on its taskbar icon? (This will make it possible to close the window by using the WinClose command.)

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

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by mikeyww » 02 Jul 2022, 11:43

I imagine that someone did it! Would search forum for "taskbar".

User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by A Keymaker » 07 Jul 2022, 21:15

Alexander2 wrote:
01 Jul 2022, 12:56
[...]
Taskbar Tweaker does not work in Windows 11
[...]
The 7+ Taskbar Tweaker? Or some other Taskbar Tweaker?

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by Alexander2 » 08 Jul 2022, 10:03

Keymaker wrote:
07 Jul 2022, 21:15
Alexander2 wrote:
01 Jul 2022, 12:56
[...]
Taskbar Tweaker does not work in Windows 11
[...]
The 7+ Taskbar Tweaker? Or some other Taskbar Tweaker?
7+ Taskbar Tweaker. The website of the program states that it does not support the Windows 11 taskbar.

I used 7+ Taskbar Tweaker on Windows 10, which was convenient, because the program made it possible not to group taskbar icons but to keep them separate. It also made it possible to close programs by middle-clicking on their taskbar icons.

User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: Closing Programs/ Windows by a Middle-click on the Taskbar

Post by A Keymaker » 12 Jul 2022, 06:53

Alexander2 wrote:
08 Jul 2022, 10:03
7+ Taskbar Tweaker. The website of the program states that it does not support the Windows 11 taskbar.
[...]
That is yet another reason for me to keep running as long as possible on Windows 10

Post Reply

Return to “Ask for Help (v1)”