#Requires AutoHotkey v2.0 #SingleInstance Force ; Context-sensitive middle mouse button ; ; Behavior: ; Cursor is I-beam (text field) → left-click to focus + position, then Ctrl+V ; Window is a known terminal → same ; Everything else → real middle click (close tab, taskbar preview, etc.) MButton:: { static terminalProcesses := ["WindowsTerminal.exe", "mintty.exe", "putty.exe", "ConEmu64.exe", "ConEmu.exe", "alacritty.exe"] ; Capture cursor shape BEFORE any clicks shouldPaste := IsIBeamCursor() if !shouldPaste { MouseGetPos(&mx, &my, &hWnd) try { proc := WinGetProcessName("ahk_id " hWnd) for name in terminalProcesses { if (proc = name) { shouldPaste := true break } } } } if shouldPaste { Click ; left-click at current position — activates window and places cursor Send("^v") } else Send("{MButton}") } IsIBeamCursor() { static iBeam := DllCall("LoadCursor", "ptr", 0, "ptr", 32513, "ptr") ci := Buffer(24, 0) NumPut("uint", 24, ci, 0) DllCall("GetCursorInfo", "ptr", ci) cursor := NumGet(ci, 8, "ptr") return cursor == iBeam }