Be careful! There is no standard way to close application therefore HotKeySet with F1 to close #include <GUIConstants.au3> Const $SC_CLOSE = 0xF060 Const $MF_BYCOMMAND = 0x0 Const $MF_GRAYED = 0x1 Const $WM_SYSCOMMAND = 0x0112 HotKeySet("{F1}", "OnF1") $gui = GuiCreate("Catch the X Click", 300, 100) GUISetState() GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND") $hMenu = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $gui, "int", 0) ;~ DllCall("user32.dll","hwnd","Delete