title: AHK: Assign hotkey only for one specific active window and not for others
body: <p>I have just done a piece of code that does the following thing. When I make a selection by mouse in Firefox or EndNote, the script sents a Ctrl+c and checks the clipboard for a regex match. If there is a match, it changes the clipboard contents and shows a tooltip. It works fine for these two programs. Adobe Acrobat sometimes shows an error when a Ctrl+c is sent (even if a user presses a ctrl-c Acrobat sometimes shows famous "There was an error while copying to the Clipboard. An internal error occurred). So it decided to assign an F9 hotkey, but it works for all programs and not just for Acrobat. How do I assign an hotkey for only one window – Acrobat? Here's my code. I know it's lame – I am a newbie to programming in general, and in AHK in particular.</p>
  
  <pre><code>#If WinActive("ahk_exe firefox.exe") || WinActive("ahk_exe EndNote.exe") || WinActive("ahk_exe Acrobat.exe")
          if WinActive("ahk_exe Acrobat.exe")
          F9::
          {
          Clipboard:=""
          send,^c
          ClipWait, 1
          ToolTip % Clipboard := RegExReplace(Clipboard, "\r\n", " ")
          SetTimer, ToolTipOff, -1000
          }
          return
  
      ~LButton::
          now := A_TickCount
          while GetKeyState("LButton", "P")
              continue
          if (A_TickCount-now &gt; 500 )
          {   
              Send ^c
              if WinActive("ahk_exe firefox.exe")
              {
                  If RegExMatch(Clipboard, "[0-9]\.\s[A-Za-z,]*\s[A-Za-z]*")
                  {
                  regex := "[0-9]\.\s*|\s?\([^)]*\)|\."
                  replace := ""
                  }
                  else If RegExMatch(Clipboard,"[0-9]{2}[-\/][0-9]{2}[-\/][0-9]{4}")
                  {
                  Clipboard := RegExReplace(Clipboard, "^0", "")
                  regex := "\/"
                  replace := "."
                  }
                  else return
              }
              else if WinActive("ahk_exe EndNote.exe")
              {
                  If RegExMatch(Clipboard, "[a-z]+\,\s[A-Z0-9‘“]")
                  {
                  regex := "\??!?\:|\?|!"
                  replace := "."
                  }
                  else return
                  }
              ToolTip % Clipboard := RegExReplace(Clipboard, regex, replace)
              SetTimer, ToolTipOff, -1000
          }
      return
  #If
  
  ToolTipOff:
      ToolTip
  return
  </code></pre>