title: Using AutoHotKey to detect focus in Git Gui
body: <p>I'm trying to write an <a href="http://www.autohotkey.com/" rel="nofollow">AutoHotKey</a> script that will activate my <a href="http://www.kernel.org/pub/software/scm/git/docs/git-gui.html" rel="nofollow">Git Gui</a> window, refresh it, and put the focus in the commit-comment text box. Activating and refreshing are no problem, but I'm not having any success changing focus. AutoHotKey doesn't seem to be correctly detecting the child controls in the Git Gui window.</p>
  
  <p>If I run AutoHotKey's Window Spy utility, switch to the Git Gui window, and put the mouse over the commit-comment text box, Window Spy shows the following output (abbreviated):</p>
  
  <pre><code>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Window Title &amp; Class )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  Git Gui (Tyler08) C:/svn/Tyler08
  ahk_class TkTopLevel
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Mouse Position )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  On Screen:  808, 727  (less often used)
  In Active Window:   816, 735
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Now Under Mouse Cursor )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  ClassNN:    TkChild18
  Text:   
  Color:  0xF0F0F0  (Blue=F0 Green=F0 Red=F0)
  </code></pre>
  
  <p>So it looks like the class name of that edit box is TkChild18, and I would expect to be able to write the following in my AutoHotKey script:</p>
  
  <pre><code>NumpadAdd::
  ControlFocus, TkChild18, Git Gui (Tyler08) C:/svn/Tyler08
  return
  </code></pre>
  
  <p>But when I start this script and then press Numpad +, nothing happens. I expected the focus to move to the commit-comment text box, but the focus doesn't change at all.</p>
  
  <p>In trying to troubleshoot this, I built the following script based on the AutoHotKey docs for ControlGetFocus:</p>
  
  <pre><code>NumpadAdd::
  ControlGetFocus, OutputVar, Git Gui (Tyler08) C:/svn/Tyler08
  if ErrorLevel
      MsgBox, The target window doesn't exist or none of its controls has input focus.
  else
      MsgBox, Control with focus = %OutputVar%
  </code></pre>
  
  <p>Now if I activate the Git Gui window and press Numpad +, AutoHotKey pops up a message box that says: "Control with focus = TkChild1". No matter where the focus is -- whether the focus is in the commit-comment text box, or in the diff pane, or in the "New Commit" or "Amend Last Commit" radio buttons, or in any of the buttons -- AutoHotKey always reports that the focus is TkChild1. This disagrees with Window Spy, which is able to see all the child windows (TkChild18, etc.)</p>
  
  <p>The above script does work with at least some other apps (as long as I change the window title in the second line). It shows its "target window doesn't exist..." failure message if a WPF element has focus (e.g. the Output window in Visual Studio 2010) but it succeeds if a WinForms control has focus (e.g. VS2010's Properties grid). So I know I've got the right syntax for the ControlGetFocus command. I suspect that Git Gui is doing something strange with its child windows (it's built with the Tk framework, which may do something weird that AutoHotKey can't handle).</p>
  
  <p>Anyone have any ideas on how I can get AutoHotKey to successfully change focus within the Git Gui window?</p>
  
  <p>Using <a href="http://www.autohotkey.com/download/" rel="nofollow">AutoHotKey Basic</a> v1.0.48.00 and <a href="http://code.google.com/p/msysgit/" rel="nofollow">mSysGit</a> version 1.7.3.1-preview20101002 on 64-bit Vista.</p>