title: Check if text caret is in a text box in AutoHotkey
body: <p>I want to be able to do different things depending on whether the text caret is in a text box or not.</p>
  
  <p>For example, if the caret is in a text box, then the backspace key functions as normal; but if it isn't then the backspace key maps to Alt+Left (previous page in Chrome).</p>
  
  <p>The following code was all I could come up with:</p>
  
  <pre><code>IsInTextBox()
  {
      clipboardCache := Clipboard
      Clipboard :=
  
      ; Try to highlight the character to the left, if something gets highlighted, then we are definitely in a text box.
      Send, +{Left}^c{Right}
      ClipWait, 0.1
      If (Clipboard = "")
      {
          Clipboard := clipboardCache
          Return False
      }
      Else
      {
          Clipboard := clipboardCache
          Return True
      }
  }
  </code></pre>
  
  <p>There are 2 problems with this method: First, it won't work if the text caret is at the start of the text box (because there are no characters to the left to be highlighted). Second, you can see the caret moving around and highlighting the character to the left.</p>
  
  <p>Is there is a way to check if the caret is focused on a text box <em>without</em> affecting what the user sees?</p>