Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My script already has many #IfWinActive lines, and I am currently using #IfWinNotActive on many of my global hotkeys to disable them when I have a certain window active. However, this is not a very clean solution and now I have more than one program I would like to disable my hotkeys for. Currently, I manually suspend and unsuspend my script, but this gets pretty tedious.

I was wondering if there's a way to automatically suspend the script when a certain program is active and unsuspend when the program loses focus.

share|improve this question

There is a way, I do this using a single #If directive at the beginning of all my scripts (prepended using #Include):

#if (!WinActive("ahk_exe sublime_text.exe") && !WinActive("Tinychat"))

This disables the hotkeys in all of my scripts if either: the process Sublime Text (executed from any directory) is active, or Tinychat is active in any browser. You can change/add conditions to this line to change/add the processes/windows/tabs you want to exclude.

share|improve this answer

If the script is suspended, then how would it un-suspend itself? Your best bet is to put the main script in a thread and have another thread responsible for suspending and resuming the first thread.

share|improve this answer
Ah yes, you are right about that. Maybe the question should be about how to disable hotkeys rather than suspend/unsuspend. Your solution requires the other thread to constantly run to check the current active window, right? or something of the sort? – Kevin Lau Jul 25 '12 at 4:21
Not necessarily. You could design your script so that the control thread simply toggles the hotkeys in the main thread using the Hotkey command. – Synetech Jul 25 '12 at 4:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.