#HotIf MouseIsOverTitlebar() ; 功能:鼠标中键点击标题关闭窗口 MButton:: { ; alternative to WinClose, as WinClose is a somewhat forceful method, e.g., if multiple Microsoft Excel instances exist, WinClose will close them all at once. ; 0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE https://autohotkey.com/docs/commands/WinClose.htm#Remarks ; https://learn.microsoft.com/zh-cn/windows/win32/menurc/wm-syscommand MouseGetPos , , &win ; 我加的,要不然它不起作用 PostMessage 0x112, 0xF060, , win ShowToolTip("窗口关闭") }
; 功能:鼠标右键点击标题最小化窗口 RButton:: { err_code := KeyWait("RButton", "T0.4") if(err_code = 0) ;超时 { Send "{Click, Right}" ; n.b., do not use Send {RButton} }else{ ; https://learn.microsoft.com/zh-cn/windows/win32/menurc/wm-syscommand MouseGetPos , , &win ; 我加的,要不然它不起作用 PostMessage 0x112, 0xF020, ,win ; alternative to WinMinimize ShowToolTip("窗口最小化") } }
; 窗口置顶功能 ~LButton:: { CoordMode "Mouse", "Screen" MouseGetPos &xOld, &yOld, &win ExStyle := WinGetExStyle(win) if (ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST { ExStyle := "窗口已取消置顶" } else { ExStyle := "窗口已置顶" } err_code := KeyWait("LButton", "T1") ; wait for the left mouse button to be released with timeout set to 1 second MouseGetPos &xNew, &yNew if(xOld = xNew && yOld = yNew && err_code = 0) ; if the mouse did not move during the timeout period { WinSetAlwaysOnTop -1, "A" ; toggle window always on top ShowToolTip(ExStyle) } }
第二部分 双击 Esc 关闭窗口
Action
+ Target
= Result
Double press
+ Esc key
= close active window
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
; 功能:双击Esc关闭窗口 #HotIf ~Esc:: { id_old := WinGetID("A") process_name := WinGetProcessName("A") KeyWait "Esc" ; wait for the Esc key to be released err_code := KeyWait("Esc", "D T0.4") if (err_code = 1){ id_new := WinGetID("A") ; get the window id after the Esc key has being pressed again win_class := WinGetClass("A") if (id_old = id_new && win_class != "Shell_TrayWnd" && win_class != "Shell_SecondaryTrayWnd" && win_class != "Progman" && win_class != "WorkerW") { ; if the current window is the same one as before and is not taskbar or desktop Send "!{F4}" } } }
; 功能,右击任务栏图标鼠标自动跳转到关闭窗口 #HotIf MouseIsOver("ahk_class Shell_TrayWnd") || MouseIsOver("ahk_class Shell_SecondaryTrayWnd") ; apply the following hotkey only when the mouse is over the taskbar ~RButton:: ; when right clicked { CoordMode "Mouse", "Screen" MouseGetPos &xOld, &yOld Sleep 500 ; wait for the Jump List to pop up, n.b., this line also helps to provide a uniform waiting experience MouseGetPos &xNew, &yNew CoordMode "Mouse", "Window" if (Abs(xNew - xOld) < 8 && Abs(yNew - yOld) < 8) ; if the mouse did not move much { Loop 6 { ifWinActive("ahk_class Windows.UI.Core.CoreWindow") ; if the Jump List pops up(right clicked on the taskbar app buttons) { WinGetPos , , &width, &height ; get the size of the last found window(Jump List) MouseMove(width / 2), (height - 3 * width / 32), 10 ; move the mouse to the bottom of the Jump List("Close window") break } Sleep 250 ; wait for more time } } }