Is there a way to create a custom hotkey in Windows that will close the current window or sub-window?

First of all, let me point out that I'm certainly familiar with the age-old Alt+F4 shortcut, so that's not exactly what I want.

Probably half the programs I use on a regular basis have the Ctrl+W shortcut that closes the current tab (in browser), spreadsheet (in Excel), or text file (in Notepad++) - just a few examples. I've grown so accustomed to using Ctrl+W that it really irks me when a program does not utilize the same hotkeys.

I've never used AutoHotkey before, but I've seen plenty of articles on its usefulness. Is this task something within the scope of an AutoHotkey script? I would want the shortcut to close the current tab or sub-window, but then close the current program after the final tab is closed.

In Chrome, this is default behavior, but I haven't seen the same in too many other applications. I love the functionality, though, and would like to port it to all Windows apps.


In AutoHotkey you can easily remap Ctrl+W per application. For instance in EditPlus Ctrl+F4 closes an MDI window.

#IfWinActive EditPlus - 
^w::Send ^{F4}

If say a menu's Close doesn't have a hotkey, you can use AltFC to open the File menu and use the accelerator.

If that fails you can use ControlClick (e.g. on a toolbar icon).
If that fails you can use PostMessage/SendMessage.

A more advanced script could certainly close the application after its children, if it doesn't already do so.


I can attest that in windows 7 the desired shortcut (Ctrl+W) work differently according to each program. In office 2003 (closes opened doc, not the window), windows explorer (closes the window), firefox (closes the tab and them the window if it's the last tab, like Chrome), notepad++ (close the tab)...

You can certainly remap any shortcut using autohotkey for closing, but implementing this new functionality present in Firefox and Chrome, in all the programs seems not possible because it is program related not Windows related like the regular ALF+F4

This site is a great place to check for examples and see what can be done with autohotkey. Good luck