Having two Windows excluded in a IfWinNotActive in AutoHotKey

autohotkey if window title contains
autohotkey while window active
autohotkey active window title
autohotkey if window focus
auto hotkey ifwinactive
autohotkey ifwinnotactive
winactivate ahk

I am mapping Alt+F4 to ESC so that I can close windows just by pressing escape. However there are two windows that I need to actually use ESC in. So, when either of these two windows are active I want to be able to press ESC without closing the window. What is the easiest way to accomplish this? I have my script working when I just am excluding one active window but I need to work when either of the two windows are active.

Here is my attempted code:

GroupAdd, ESC, Untitled - Notepad
GroupAdd, ESC, 

#IfWinNotActive, ahk_group, ESC

This is the code that works properly with just one window:

;#IfWinNotActive, Untitled - Notepad

UPDATE: Should this work?

SetTitleMatchMode, 2
SetTitleMatchMode, 2
#IfWinNotActive, Untitled - Notepad
#IfWinNotActive, Document 1 - Microsoft Word

You have an extra comma in your #IfWinNotActive line after ahk_group

Try the following:

GroupAdd, ESC, Untitled - Notepad
;  Add more windows to the group if necessary

#IfWinNotActive, ahk_group ESC

Having two Windows excluded in a IfWinNotActive in AutoHotKey , You have an extra comma in your #IfWinNotActive line after ahk_group. Try the following: GroupAdd, ESC, Untitled - Notepad ; Add more  In other words, if IfWinActive evaluates to "true" or IfWinNotActive evaluates to "false", the Last Found Window will be updated. The function WinActive() returns the Unique ID (HWND) of the active window if it matches the specified criteria. If it does not, the function returns 0.

Try using SetTitleMatchMode.


2: A window's title can contain WinTitle anywhere inside it to be a match.

Then you can do this (it is case-sensitive by default):

settitlematchmode, 2
#IfWinNotActive, Untitled - 

Try this:

First, you can't remap the same key twice in the same script.

This command affects the behavior of all windowing commands, e.g. IfWinExist and WinActivate.

Second, you stack lines like this:

#IfWinNotActive, Untitled - Notepad
#IfWinNotActive, Document 1 - Microsoft Word

you are saying, if win1 is not active, THEN if win2 is not active.

Try this, instead:

settitlematchmode, 2
app1 := winexist("other app")
app2 := winexist("Untitled - Notepad")

if(app1 || app2)    ;the || means OR.  you can use && for AND.
    Escape::!F4   ;you can only map a particular key one time per script

or this, which is more along the lines of your approach:

settitlematchmode, 2
GroupAdd, ESC, Untitled - Notepad
GroupAdd, ESC, My other window
IfWinNotActive, ahk_group ESC

Is there a way to exclude multiple titles from GroupAdd?, I'm hoping for something more elegant than each hotkey having an IfWinNotActive ahk_group exceptions clause. I want the hotkey to work  In other words, if WinActive or IfWinActive evaluates to true or IfWinNotActive evaluates to false, the Last Found Window will be updated. An easy way to retrieve the unique ID of the active window is with ActiveHwnd := WinExist("A"). Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been

This worked for me:

1: write this at the top of your script (before the first hotkey):

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode, Regex 

2: Then you can use the not operator !:

if !(WinActive("ahk_class Notepad") or WinActive("ahk_class Calculator")) {


Collection of AutoHotkey scripts I use · GitHub, for Skype, I also like the text box to have focus, so that it's ready to type text RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\​Windows\CurrentVersion\Explorer\Advanced, Hidden, 2 exclude MSTSC, which uses Ctrl+Alt+End for Ctrl+Alt+Delete. IfWinNotActive, ahk_class TscShellContainerClass. ; This hotkey will have no effect if pressed in other windows (and it will "pass through"). #c::MsgBox You pressed Win-C while Notepad is active. ::btw::This replacement text for "btw" will occur only in Notepad. #IfWinActive #c::MsgBox You pressed Win-C in a window other than Notepad.

Cannot disable key mapping for VirtualBox : AutoHotkey, #IfWinNotActive, VirtualBox CapsLock::Ctrl #IfWinNotActive #IfWinNotActive, [​Running] The exact window title is "Ubuntu [Running] - Oracle VM VirtualBox". Discussion 2: Connecting & starting a page in Chrome with AutoHotkey Excluding the blank window from activation ; doesnt work and doesnt end up activating  Why you should learn AutoHotkey. AutoHotkey Resources. Installing AutoHotkey and AHK Studio. Recommended Default Settings. Various Types of Send. Using a SetTimer. Creating, reading and writing initialization files (.ini files) Working with the Windows Registry. Utilizing Controls (over 40 videos on this alone!) Selecting menus in (older

notitle bar AHK on pokerstars, help please, Having two Windows excluded in a IfWinNotActive in AutoHotKey GroupAdd, ESC, Untitled - Notepad ; Add more windows to the group if  Help with getting Windows to perform two functions LWin:: KeyWait,LWin KeyWait,LWin,D T0.3 If ErrorLevel send {lwin} else send {f4} The code above works just fine except that Lwin key no longer works as a modifier.

Autohotkey - Search Digi-Key Faster, Working for PokerStars 7 and Windows 10. #SingleInstance force ; Exclude the desktop ; Note: Also excludes "My Computer" accidental Metro interface clicks (​Win 8+) #IfWinNotActive ahk_exe explorer.exe ; Set your 2) If supermaxing a background window that has menus within the Caption bar (e.g.  I've searched using various efforts online and have checked multiple AHK documentation pages and forum posts before getting to this point of defeat. That said, here's the struggle There are a few hated hotkeys I've run across over time such as the one that sets you at a low resolution low bit color hotkey, or the windows gaming hotkey winkey G.

  • So if the two windows I want excluded have completely different titles it should look like this, correct? See change above.
  • This seems to overcomplicate it. He should be able to add the SetTitleMatchMode 2 and simply add more windows to the group.
  • Thanks for both of your guys help on this. It seems that that something in the rest of my script was causing it to fail. When I used just this block of code, the script executed properly. But, when it was in the rest of the script the windows still closed. Anyway, last question...is there a reason that when one of the two windows is active the rest of the code doesn't run? I thought that this was the purpose of the "Return".