TL;DR
Alt-F4 [ !F4 ] may be used to close a program. If you want that NOT to apply to a particular program, e.g. Notepad++:
$!F4::
;prevent Alt-F4 from closing Notepad++ [0]
IfWinActive ahk_class Notepad++
{
return
}
Send, !{F4}
return
#SingleInstance force SetTitleMatchMode, 2 RemoveToolTip20: SetTimer, RemoveToolTip, Off ToolTip,,,,20 return halfWidth := (A_ScreenWidth / 2) halfHeight:= (A_ScreenHeight / 2) $!F4:: ;prevent Alt-F4 from closing Notepad++ [0] IfWinActive ahk_class Notepad++ { msg:="You said to leave Notepad++ open" Tooltip, %msg%, %halfWidth%, %halfHeight%, 20 SetTimer, RemoveToolTip20, 800 return ; take no further action } ;if Firefox Exists then do NOT close ANY window else IfWinExists ahk_class Firefox { msg := "Click the red X in the top right if you really want Firefox closed" Tooltip, %msg%, ( halfWidth / 8 ), %halfHeight%, 20 SetTimer, RemoveToolTip20, 800 return ; ignore Alt-F4 }else{ msg := "I'm melting..." Tooltip, %msg%, %halfWidth%, %halfHeight%, 20 SetTimer, RemoveToolTip20, 800 Send, !{F4} ; actually send Alt-F4 for all other programs } return[0] The Title of Notepad++ may change depending on which file is open. For other programs that have a fixed title you can use:
IfWinActive, Open Database - NewDatabase.kdbx { return }KeePass always has, (for this author) the fixed title, (while opening) of "Open Database - NewDatabase.kdbx" so we can skip the ahk_class
N.B.
IfWinActive only considered the window that you are looking at.IfWinExists changes the behavior on a window that you may have Active or may be minimised.