2

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.

0

2 Answers 2

5

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.

-1

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.

2
  • 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?
    – Evie
    Jul 25, 2012 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, 2012 at 4:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .