Key Customizing [Esc] to close Windows


  1. Posts : 170
    Windows Seven x64
       #1

    Key Customizing [Esc] to close Windows


    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


  2. Posts : 61
    7 HP & ULT
       #2

    Within Windows, I don't know how...but with AutoHotKey, it's easy.

    AutoHotkey - Free Mouse and Keyboard Macro Program with Hotkeys and AutoText
      My Computer


  3. Posts : 41
    Windows 7 Home Premium 32bit
       #3

    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 by alishibaz; 24 Oct 2011 at 17:24.
      My Computer


  4. Posts : 41
    Windows 7 Home Premium 32bit
       #4

    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 by alishibaz; 24 Oct 2011 at 17:14.
      My Computer


  5. Posts : 457
    Microsoft Windows 10 Home Build 15036
       #5

    Jeez....is Alt-F4 so hard?
      My Computer


  6. Posts : 41
    Windows 7 Home Premium 32bit
       #6

    PeaB4YouGo said:
    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


  7. Posts : 2
    Windows 7 Professional 64bit
       #7

    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


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:20.
Find Us