Please note that when using AHK (Auto Hotkey), the definition of a hotkey is a key combination (such as F6 or ALT-X or CTL-SHIFT-HOME) such that whenever you press that key combination the response is identical to some other keyboard combination.
Here is one definition of the ESCAPE key contained in an AHK script file (also known as an "AHK hotkey definition file") that causes the ESC key to behave identically as if you pressed the keyboard combination "ALT+F4".
ESCAPE::SendInput !{F4} ; close active window
Note that in the above definition:
1) everything to the right of the semicolon is a comment.
2) The above definition specifies that whenever the user presses the ESCAPE key, the effect is identical to that as if the user pressed and held down the ALT key and then pressed and released the F4 key and then released the ALT key.
There are many additional remarks I could make such as how to restore the original use of the ESCAPE key temporarily - especially since there are several different ways to define "temporarily".
1) One way to define "temporarily" is that you may wish to have the ESCAPE key used in its original way for just for a single keypress and then go back to its new meaning of "ALT-F4".
2) A second way is to stop using the ESCAPE key in this new way for a time, and then revert back to using it when you are ready. In this case you can define one hotkey that will cause the ESCAPE key to be used in this new way. Also, you can define a second hotkey that will cause the ESCAPE key to revert back to its original meaning.
In the following example, the hotkey SHIFT-F1 loads the AHK hotkey definition file "h1.ahk" which is equivalent to having the ESCAPE key defined as the sequence "ALT+F4".
Also the hotkey SHIFT-F2 loads the AHK hotkey definition file "h2.ahk" which is equivalent to having the ESCAPE key defined in its original way. In other words, pressing ALT+F1 causes the ESCAPE key to be used in a new manner which is equivalent to: everytime you press the ESCAPE key, the effect would be identical to your pressing ALT+F4.
Also, pressing ALT+F2 causes the ESCAPE key to be used in its original way. In this way, you have control over the use of the ESCAPE key. By pressing SHIFT+F1, you can cause the ESCAPE key to be used in its new manner (which is the same as pressing ALT+F4). You can use it in this new way for as long as you like and when you wish to revert back to its original usage, you can press SHIFT+F2 and that will ensure the pressing the ESCAPE key will have the same effect as it originally did.
-------------------------------------------------------------------------------------------
Please assume the text file "H1.AHK" contains the following three statements: This file is usually referred to as an AHK "Hotkey Definition File" or an AHK "Script File" and it contains the definitions of the hotkeys that will be used to affect their new meanings. I named this first file "H1" just to refer to the fact that it is a file of "(H)otkeys" and it is my first or primary file of AHK hotkeys.
+F1:: ; load script file h1.AHK
run %programfiles%\autohotkey\autohotkey.exe C:\AHK\h1.ahk
exitapp ; "exitapp" eliminates the requirement for any "Return" stmt
+F2:: ; load the new script file (H2.AHK)
run %programfiles%\autohotkey\autohotkey.exe C:\AHK\h2.ahk
exitapp ; "exitapp" eliminates the requirement for any "Return" stmt
ESCAPE::SendInput !{F4} ; close active window
;---------------------------------------------------------------------------------------
Please assume the text file "H2.AHK" contains the following two statements: This file is identical to "H1.AHK" except that it does not contain the third statement which defines the ESCAPE key to send the key sequence: "ALT + F4".
This file is usually referred to as an AHK "Hotkey Definition File" or an AHK "Script File" and it contains the definitions of the hotkeys that will be used to affect their new meanings. I named this second file "H2" to refer to the fact that it is a file containing "(H)otkeys" and it is my second such AHK definition file.
+F1:: ; load script file h1.AHK
run %programfiles%\autohotkey\autohotkey.exe C:\AHK\h1.ahk
exitapp ; "exitapp" eliminates the requirement for any "Return" stmt
+F2:: ; load the new script file (H2.AHK)
run %programfiles%\autohotkey\autohotkey.exe C:\AHK\h2.ahk
exitapp ; "exitapp" eliminates the requirement for any "Return" stmt
;---------------------------------------------------------------------------------------
In these examples, the hotkey SHIFT+F1 loads the script file named "h1.ahk" and
the hotkey SHIFT+F2 loads the script file named "h2.ahk".
+F1:: ; load script file h1.AHK
run %programfiles%\autohotkey\autohotkey.exe C:\AHK\h1.ahk
exitapp ; "exitapp" eliminates the requirement for any "Return" stmt
+F2:: ; load the new script file (H2.AHK)
run %programfiles%\autohotkey\autohotkey.exe C:\AHK\h2.ahk
exitapp ; "exitapp" eliminates the requirement for any "Return" stmt
Finally, please note that the script file "h1.ahk" and "h2.ahk" have both been saved in a folder named "C:\AHK"". This folder is not in any way a system folder. It is just used to save my AHK hotkey definition files.