Windows - Alt 单击窗口以关闭鼠标光标下的窗口

Windows - Alt 单击窗口以关闭鼠标光标下的窗口

是否可以单击窗口内的任意位置来关闭窗口?按住 alt 键,然后单击要关闭的窗口。就像在游戏中射击目标一样。

为什么不按 Alt+F4?这样会更有用,因为 Alt+F4 要求窗口处于活动状态。如果不是,您必须先单击窗口以将其置于最前面。额外的步骤。

答案1

Alt & RButton:: 
   MouseGetPos, , , id,
   WinGetClass, class, ahk_id %id%

   ; disable for windows taskbar 
   If class not in Shell_TrayWnd
        WinClose, ahk_id %id%
return

这对我来说非常有效。

(可选)为了防止此操作在某些窗口上起作用,只需将该窗口的类添加到上面的过滤器中。首先,从上下文菜单 Autohotkey 托盘图标中的“窗口间谍”功能中找出应用程序的 ahkclass。然后只需在后面添加类名即可。

   ;If class not in Shell_TrayWnd, <insert yourapp classname>

改编自, https://autohotkey.com/board/topic/43348-close-window-under-mouse/

答案2

修改过的回答对于 AHK v2

#Requires AutoHotkey v2.0

Alt & RButton:: {

MouseGetPos ,, &id
; detect the unique ID number of the window under the mouse cursor
; The window does not have to be active to be detected. Hidden windows cannot be detected
; WinID := WinExist("A")  ; alternative - but 'Active' window might not always be the intended target

winClass := WinGetClass("ahk_id " id) ; Retrieves the specified window's class name
If (winClass != "Shell_TrayWnd"                         ; exclude windows taskbar
 || winClass != "TopLevelWindowForOverflowXamlIsland"   ; System tray overflow window
 || winClass != "Windows.UI.Core.CoreWindow"            ; Notification Center
;|| winClass != "insert yourapp's classname"            ; uncomment to add more apps
    )
    WinClose("ahk_id " id)  ; sends a WM_CLOSE message to the target window
    ; PostMessage 0x0112, 0xF060,,, "ahk_id " id ; alternative - same as pressing Alt+F4 or clicking a window's close button in its title bar
}

^!F4::WinKill "A"

/* ; alternative
^!F4:: {
MouseGetPos ,, &id
ProcessClose WinGetProcessName("ahk_id " id)
}
; other methods to quit app - https://www.xda-developers.com/how-force-quit-applications-windows/
*/

答案3

AltSnap,免费开源程序,允许您执行上述操作以及更多操作(按住 ALT 按钮拖动/调整窗口大小)。它在 Windows 10 中运行良好。

您可以设置要排除在黑名单之外的窗口。

在此处输入图片描述

相关内容