AHK 2 script to activate taskbar windows and tray icons on Mouse-down not Mouse-up (working code included!)

v2 Tool / Script Share

When you click on say, recently created tabs in Chrome, the page displays incredibly quickly, and one of the big reasons behind this is the use of LMB mouse-down (instead of mouse-up). It switches to the tab before you even release the mouse button (mouse-up). That feels nice. It's smooth and reduces latency to a minimum.

Windows tabs from the taskbar and tray don't work like that and instead use mouse-up. Feels a bit sluggish subconsciously, but it's even worse when you click a program tab, move the mouse quickly to use said program, and find the window hasn't been activated. What's actually happened is you've clicked in the right place initially, but released the button while the cursor was briefly moved and so isn't on the tab anymore.

Instinctively, you click the tab again, and it works this time. You're frustrated, but not actually quite sure what happened. You just know Windows didn't respond to your input in the way you imagined it should.

So for months, I've been trying to find code to implement this feature in Windows 11. I'm not going to lie - I used AI to help. But it's taken dozens of attempts and near misses. Finally, using the latest Grok 4.2 I've got something workable:

#Requires AutoHotkey v2.0
#SingleInstance Force

; === Detect taskbar APP icons ONLY (excludes tray/clock/start so their RMB menu stays untouched) ===
IsTaskbarAppIcon() {
	MouseGetPos(,, &winID, &ctrl)
	winClass := WinGetClass("ahk_id " winID)
	if !(winClass = "Shell_TrayWnd" || winClass = "Shell_SecondaryTrayWnd")
		return false
	; Win10/11 compatible: skip known tray areas (works even when ctrl="" on Win11 icons)
	if RegExMatch(ctrl, "i)(TrayNotifyWnd|SysPager|ToolbarWindow32.*Notification|Clock|Start)")
		return false
	return true
}

; === Your original L-click-on-press (fixed to NOT break RMB drag) ===
~LButton::
{
	if (GetKeyState("RButton", "P"))   ; ← only 1 line added
		return
	MouseGetPos( , , &winID)
	winClass := WinGetClass("ahk_id " winID)
	if (winClass = "Shell_TrayWnd" || winClass = "Shell_SecondaryTrayWnd")
		Send "{LButton up}"
}

; === RMB = drag on taskbar app icons only ===
#HotIf IsTaskbarAppIcon()
RButton:: {
	Send "{Blind}{LButton down}"
	KeyWait "RButton"
	Send "{Blind}{LButton up}"
}
#HotIf

The only difference is that you use RMB to drag the icons instead of the usual LMB, as LMB dragging would interfere with the mousedown event feature. No biggie. RMB on taskbar icons is next to useless normally anyway.

Anyway, the point of my post is two-fold: One to help users here who want to experience the joy of a snappier Windows UI. The second is to ask if the code can be simplified with any small corrections or bugs you might notice.

Posted Feb 19, 2026, 3:42 PM UTC · edited

117
Loading comments…