Key Customizing [Esc] to close Windows

zezasu

New member
Power User
Local time
1:59 PM
Messages
170
Location
Wildomar
Basically, all I want to be able to do is use the [ESC] button to close windows (ie Browsers,apps, games, anything that if selected and when a button is pressed will close it) in windows 7.

I always thought this would be good but is there anyway to make it do that from inside windows without some other software. If there isn't, then what other 3rd party programs can let me do this in Windows.

I have searched, not as heavy as I think i should, but all i keep seeing in Visual Basic and C++ programing, something I'm not good at.


If anyone can help it would be cool. It doesn't have to be [esc] but i would prefer it.



[Sorry if its in the wrong area, but this seemed to make sense, please feel free to move it if it does not belong here or you think it would be better in a another place on the forums. ]
 

My Computer

Computer Manufacturer/Model Number
ZezasuBuilt
OS
Windows Seven x64
CPU
Intel Core 2 Quad Q6700 3.2Ghz
Motherboard
GA-UD3P Intel and Crossfire ready
Memory
6GB Samsung
Graphics Card(s)
5850 Sapphire Toxic Edition
Sound Card
On Board relTek
Monitor(s) Displays
23inch LG W2343T Dual Montiors
Screen Resolution
1920-1680 Dualmonitors
Hard Drives
Western Digital 7200. X 2 (500gb)
Sega 7.2 X 2 (500gb)
PSU
Corsair HX650W
Case
Lian Li Lan Cool PC-k7
Cooling
Artic Freezer 7 Artic Case fans
Keyboard
Logitech illuminated keyboard
Mouse
Logitech Trackball
Internet Speed
1MB down 500k UP (10mb D /1mb U )
Other Info
Windows 7, have yet to reinstall :)
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.
 
Last edited:

My Computer

OS
Windows 7 Home Premium 32bit
I'm sorry the above post is so long. I made it long in order to make it as clear as possible.

I hope those of you who will try to use AHK, will eventually come to see that it was a good choice and that it was the best way to explain how to use "hotkey definition files" as simply as possible.

I'd just like to say that AHK is the single best tool I have ever used with Windows and I can't imagine any other tool that could be as useful or as valuable to me than AHK.
 
Last edited:

My Computer

OS
Windows 7 Home Premium 32bit
Jeez....is Alt-F4 so hard?
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
iBuyPower NZXT
OS
Microsoft Windows 10 Home Build 15036
CPU
Intel(R) Core(TM) i7-860 @ 2.80GHz
Motherboard
Gigabyte Technology Co., Ltd. P55-UD3L
Memory
4.00 GB
Graphics Card(s)
NVIDIA GeForce GTX 750
Sound Card
(1) Line 6 UX2 (2) Realtek High Definition Audio
Monitor(s) Displays
23" acer
Screen Resolution
1920 x 1080 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
(1) WDC WD5000AAKS-00D2B0 ATA Device (2) Seagate FreeAgent Go 250G USB Device
Cooling
Corsair H75 liquid cooler (Very easy to install, actually)
Internet Speed
60M cable modem-->Linksys E1200-->1Gbps net card
Browser
Chrome
Other Info
This is probably the longest I've ever had a Windows machine run without having to restore it to scratch. I'm used to restoring to "factory" about every 2 yrs. I've run with Win7 since new in 2009 and only recently (Nov, '14) restored to clean up the machine from all my 'xperimenting. LOL!! I may never need another machine.

Upgraded to 10 when it was still free, then installed 2017 update.
Jeez....is Alt-F4 so hard?


You are correct, of course. No one would do this for just ALT-F4.
But, I'm pretty sure the OP is looking for a general technique that would include all manner of keys like ALT-F4.
In my main Windows AHK script file, I have hundreds of hotkey definitions that do all manner of useful things.
 

My Computer

OS
Windows 7 Home Premium 32bit
Big thanks to alishibaz for the script. I tried doing this a number of years ago and failed miserably. Found this post and wallah, Esc is my ejector button!
 

My Computer

OS
Windows 7 Professional 64bit
Back
Top