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

autohotkeykeyboard shortcutswindows 7

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.

Best Answer

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.

Related Question