我使用本地应用程序,当按下ESCAPE时,当前窗口关闭。我想避免这种情况所以我用AutoHotKey创建了一个脚本来检测应用程序中窗口的名称,如果我按ESCAPE,窗口就不会关闭(除非我按下X)。
QSpinBox { border-width: 2px; border-style: solid; border-color : red; } QSpinBox:hover { border-width: 2px; border-style: solid; border-color: blue; }
#IfWinActive ahk_class name_of_app_class_here
现在我想在该窗口关闭时(通过按X)应用代码,但我在论坛或帮助中找不到任何解决方案。 例如:
Escape::return
#IfWinActive ahk_class name_of_app_class_here
OnWindowClose
希望它得到很好的解释。 谢谢!
答案 0 :(得分:0)
以下代码应该达到您想要达到的目的:
;tested on Notepad (Windows 7)
;note: may not work correctly if aero mode is on
;note: if you click a Notepad window that is *not* the active window, it will be closed
;note: some programs don't return the standard NCHITTEST value for a close button,
;a workaround is to compare the cursor position against the window coordinates
#IfWinActive, ahk_class Notepad
LButton::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass not in Notepad
Return
CoordMode, Mouse, Screen
MouseGetPos, vPosX, vPosY, hWnd2
if (hWnd = hWnd2)
{
SendMessage, 0x84, 0, vPosX|(vPosY<<16), , ahk_id %hWnd% ;WM_NCHITTEST
vNCHITTEST := ErrorLevel ;(8 min, 9 max, 20 close)
if (vNCHITTEST = 20)
{
MsgBox can't close me! ;put your code here
Return
}
}
SendInput {LButton Down}
KeyWait, LButton
SendInput {LButton Up}
Return
#IfWinActive
注意: 下面链接中发布的代码实现了相关的功能,捕获所有窗口的关闭按钮,而不只是针对一个程序,无论它们是活动还是非活动。
Is it possible to catch the close button and minimize the window instead? AutoHotKey