Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Close windows by middle clicking on task bar


  • Please log in to reply
20 replies to this topic
Ivan
  • Guests
  • Last active:
  • Joined: --
Just a small script to close windows by middle clicking on their button in the task bar:

http://ludios.org/me...iddle-close.ahk - please read the comments at the top.

It can be used standalone but I really recommend it with Taskbar Shuffle. Unless several people test it, I can't claim it is bug-free enough to not send Alt-F4 to the wrong place. Don't use it with unsaved work open.

If anyone has any ideas on how to improve it (it's only 8 lines of actual code), let me know.

Ivan
  • Guests
  • Last active:
  • Joined: --
In case anyone was interested: the Taskbar Shuffle author says he'll include the functionality in the next version.

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007
can you tell me please how to close a window by right clicking on its taskbar tab

thanks

TK
  • Guests
  • Last active:
  • Joined: --

If anyone has any ideas on how to improve it (it's only 8 lines of actual code), let me know.


Try this one

enablePosCheck = 1
taskBarHeight = 23
StartY = % A_ScreenHeight - taskBarHeight
CoordMode, Mouse, Screen
~MButton::
MouseGetPos, x, y, window, control
If (y > StartY or enablePosCheck == 0) {
StringGetPos, pos, control, ToolbarWindow
if ErrorLevel {
} else {
Click
Click
Send {RButton}
Sleep, 100
Send, c{ENTER}
}
}
return 8) 8)

TK
  • Guests
  • Last active:
  • Joined: --

If anyone has any ideas on how to improve it (it's only 8 lines of actual code), let me know.


EVen better version i guess would be this

enablePosCheck = 1
taskBarHeight = 23
StartY = % A_ScreenHeight - taskBarHeight
CoordMode, Mouse, Screen
~MButton::
MouseGetPos, x, y, window, control
If (y > StartY or enablePosCheck == 0) {
    StringGetPos, pos, control, ToolbarWindow
    if ErrorLevel {
    } else {
       Send, {RButton}
       Sleep, -1
       Send, c
    }
}
return

As this doesn't send Alt+F4 :!:

And just missed to appreciate ur initial work in the last post dude
Fantabulous keep it up!!


8)

danalec
  • Members
  • 225 posts
  • Last active: Oct 03 2014 05:31 PM
  • Joined: 20 Jul 2006
this is more secure, using ControlFromPoint by Lexikos and similar menu closing method by TK. Enjoy!
#NoEnv
SetBatchLines, -1
CoordMode, Mouse, Screen

~$MButton::
	MouseGetPos, X, Y, win, control
	if (control == "ToolbarWindow322") {
		WinGetPos, wX, wY,,, ahk_id %win%
		X -= wX, Y -= wY
		hwnd := ControlFromPoint(X, Y, "ahk_id " win,"", cX, cY)
		PostMessage, 0x204, 0x2 | 0x1, cX & 0xFFFF | (cY & 0xFFFF) << 16,, ahk_id %hwnd%
		PostMessage, 0x205, 0x0, cX & 0xFFFF | (cY & 0xFFFF) << 16,, ahk_id %hwnd%
		WinWait,ahk_class #32768,,1
		PostMessage,0x100,0x43,0x002E0001,,ahk_class #32768
		PostMessage,0x101,0x43,0xC02E0001,,ahk_class #32768
	}
return

ControlFromPoint(X, Y, WinTitle="", WinText="", ByRef cX="", ByRef cY="", ExcludeTitle="", ExcludeText="")
{
	if !(hwnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText))
		return false
	VarSetCapacity(pt,8)
	VarSetCapacity(wi,60), NumPut(60,wi)
	DllCall("GetWindowInfo","uint",hwnd,"uint",&wi)
	NumPut(X + (w:=NumGet(wi,4,"int")) - (cw:=NumGet(wi,20,"int")), pt,0)
	NumPut(Y + (h:=NumGet(wi,8,"int")) - (ch:=NumGet(wi,24,"int")), pt,4)
	Loop {
		child := DllCall("ChildWindowFromPointEx","uint",hwnd,"int64",NumGet(pt,0,"int64"),"uint",0x5)
		if !child or child=hwnd
			break
		DllCall("MapWindowPoints","uint",hwnd,"uint",child,"uint",&pt,"uint",1)
		hwnd := child
    }
    cX := NumGet(pt,0,"int")
    cY := NumGet(pt,4,"int")
    return hwnd
}

                                  [ profile ]


TK
  • Members
  • 1 posts
  • Last active: Jul 22 2008 06:16 PM
  • Joined: 22 Jul 2008
good job, thanks
secure but lil lengthier :)
AHK = A hot keyboard

danalec
  • Members
  • 225 posts
  • Last active: Oct 03 2014 05:31 PM
  • Joined: 20 Jul 2006
my solution would not work in all languages because it uses the "right click + c", the best solution yet is from lexikos in http://www.autohotke... ... 788#168788 although the else for "click m" is fugly :p...

                                  [ profile ]


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

this is more secure, using ControlFromPoint by Lexikos and similar menu closing method by TK. Enjoy!

Why not avoid Alt+F4 and menus entirely?

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009

this is more secure, using ControlFromPoint by Lexikos and similar menu closing method by TK. Enjoy!

Why not avoid Alt+F4 and menus entirely?

that script doesn't work for me: instead of closing a program's window - it open a window that suggests me to shutdown my PC.
+ it kills autoscrolling in the Firefox: when middleclick is pressed, while it's being held - if the cursor was moved - after that releasing middle click should stop the autoscrolling, but it doesn't.

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009

this is more secure, using ControlFromPoint by Lexikos and similar menu closing method by TK. Enjoy!

not working

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009

Just a small script to close windows by middle clicking on their button in the task bar:

http://ludios.org/me...iddle-close.ahk - please read the comments at the top.

Not working.

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009

Try this one

not working

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009

EVen better version i guess would be this

not working too.

iDrug
  • Members
  • 389 posts
  • Last active: Oct 11 2015 09:24 PM
  • Joined: 13 Oct 2009
Here is the working script:
~MButton::
    MouseGetPos,,, win
    ifWinExist, ahk_id %win% ahk_class Shell_TrayWnd
        Send {Click}!{F4}
return

Howeverm if you middle-click a free space on taskbar - you'll trigger a prompt of PC shut down.