title: How to activate a function everytime the target window becomes active in AutoHotkey
body: <p>I would like to activate a sound profile every time I switch to a specific program and change back to the default profile every time I leave it. 
  This action is turned on in a GUI via a radio button.</p>
  
  <p>The workaround I have created is:</p>
  
  <pre><code>Auto_Ftsps:
      gui, Submit, NoHide
      While (Rad3==1)
      {
          Previous_window:= WinActive("A")
          Sleep,1000
          Current_window:= WinActive("A")
          If (Previous_window =Current_window)
              {}
          Else If (Previous_window !=Current_window) 
          {
              If(WinActive("Fortnite"))
                  Run_Peace_Profile("Ftsps")
              Else 
                  Run_Peace_Profile("Graphic EQ")
          }
          Sleep,2000
      }
      return
  </code></pre>
  
  <p>Is there a better way to do this? I looked on forums and tutorials with no success.</p>