Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Middle click on taskbar button to close apps (Windows 10)



  • Please log in to reply
4 replies to this topic
joefango
  • Members
  • 56 posts
  • Last active: Jan 20 2018 02:44 PM
  • Joined: 02 Jun 2013

Hello,

 

I've been using this basic script for a long time but since Windows 10 it doesn't work anymore. Anyone got this script feature ?

;This script doesn't work on Windows 10 but very well on 7 and 8

MButton::
{
	MouseGetPos, xpos, ypos, WinID, ControlUnderMouse
	If (ControlUnderMouse = "MSTaskSwWClass1" || ControlUnderMouse = "ApplicationManager_DesktopShellWindow" || ControlUnderMouse = "Shell_TrayWnd1" || ControlUnderMouse = "MSTaskListWClass1")
	{
	MouseClick, Right, %xpos%, %ypos%
	Sleep, 200
	Send, {Up} ;I can't remember if this is correct since i've changed it for tries on windows 10)
	Send, {Enter}
	return
	}
	Else MButton::MButton
	return
}


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
That script does not work on any version of Windows.

You would need to remove the invalid line Else MButton::MButton. You can't "execute" a hotkey or remapping like you execute a command or function. They are more like directives or labels. The hotkey MButton:: executes whenever the user presses MButton, and at that point what you want to do is have it perform a click (MouseClick Middle or Send {MButton}), not "remap" the button.

If I remove that line, the script works okay on my Windows 10 system.

If you want the script to override middle click only while the cursor is hovering over the taskbar buttons, you can write it like this:
ShouldActivateMButton() {
    MouseGetPos, xpos, ypos, , ControlUnderMouse
    return ControlUnderMouse = "MSTaskSwWClass1"
        || ControlUnderMouse = "ApplicationManager_DesktopShellWindow"
        || ControlUnderMouse = "Shell_TrayWnd1"
        || ControlUnderMouse = "MSTaskListWClass1"
}

#If ShouldActivateMButton()

MButton::
    MouseClick, Right
    Sleep, 200
    Send, {Up}
    Send, {Enter}
    return
At minimum, you would need to check for MSTaskListWClass1 on Windows 10. I'm not sure whether all of the others are correct or necessary.

Braces have no effect for hotkeys/labels, so I removed them.

The following also works for me; it might be more reliable (for English systems):
; Add #If etc here if needed.

MButton::
    Send +{RButton}
    WinWait ahk_class #32768,, 1  ; Menu
    if !ErrorLevel
        Send c  ; Close
    return


joefango
  • Members
  • 56 posts
  • Last active: Jan 20 2018 02:44 PM
  • Joined: 02 Jun 2013

Thanks taking the time to answer, I slowly learn Autohotkey

 

The first script you showed me works partially because sometimes it pin the task to the taskbar intead of close it:

ShouldActivateMButton() {
    MouseGetPos, xpos, ypos, , ControlUnderMouse
    return ControlUnderMouse = "MSTaskSwWClass1"
        || ControlUnderMouse = "ApplicationManager_DesktopShellWindow"
        || ControlUnderMouse = "Shell_TrayWnd1"
        || ControlUnderMouse = "MSTaskListWClass1"
}

#If ShouldActivateMButton()

MButton::
    MouseClick, Right
    Sleep, 200
    Send, {Up}
    Send, {Enter}
    return

The second script worked well thanks I didn't know that the shift key invoked another menu!.

Anyway it seems that the Shift+RightClick activates the apps before it close them. I would prefer to not but it works

; Add #If etc here if needed.

MButton::
    Send +{RButton}
    WinWait ahk_class #32768,, 1  ; Menu
    if !ErrorLevel
        Send c  ; Close
    return


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
✓  Best Answer
The first script you showed me works partially because sometimes it pin the task to the taskbar intead of close it:

 

No doubt so would the original script (if you removed the erroneous line), since it sends the same click/keystroke with the same timing.

 

If you try doing it manually, you'll probably encounter the same problems: the jump list remembers which item was focused last, or focuses recent/pinned documents instead of the tasks (pin/close).  Pressing Tab and then End (Send {Tab}{End}) after right-clicking seems to work better.

 

Anyway it seems that the Shift+RightClick activates the apps before it close them.

 

That's probably because it shows the window's own menu (like right-clicking the title bar or left clicking the icon in the title bar), which won't accept keyboard input unless the window is active.

 

If there are multiple windows belonging to that button, it activates the taskbar (ahk_class Shell_TrayWnd) and shows a different menu which allows you to close all windows.

 

The only other approach I've seen for middle-click-close which would work on Windows 10 is to do a left-click and then close the active window, but that obviously also requires activating the window.

 

 

Edit:  I remembered a program that does what you want, among other things.  However, I haven't tested it on Windows 10 (only 7), but it looks like Windows 10 compatibility was added recently: 7+ Taskbar Tweaker



joefango
  • Members
  • 56 posts
  • Last active: Jan 20 2018 02:44 PM
  • Joined: 02 Jun 2013

Thanks! I tried Tab then I tried End but didn't try the both one after one! :shy:

 

Now it works perfectly:

ShouldActivateMButton() {
    MouseGetPos, xpos, ypos, , ControlUnderMouse
    return ControlUnderMouse = "MSTaskListWClass1"
}

#If ShouldActivateMButton()
MButton::
    MouseClick, Right
    Sleep, 200
    Send, {Tab}{End}
    Send, {Enter}
    return

Ps: I know the 7+ Taskbar software but I don't want an additional task, anyway I always wondered how work their method...