title: Using AutoHotkey to click a button within a window
body: <p>I want to make an AutoHotkey script to change the font in the PuTTY SSH client. (I prefer a small font for high information density, but when I'm showing something to a coworker, they need to be able to see it clearly.) I've gotten this far:</p>
  
  <pre><code>#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  #SingleInstance force  ; Lets the RunMe plugin for Notepad++ reload the script with Shift-F5.
  
  #IfWinActive ahk_class PuTTY    ; If PuTTY is active
    ^+1::                         ; and Ctrl-Shift-1 is pressed
    {
      Send !{Space}               ; Alt-Space to open the system menu
      Send g                      ; open Change Settings
      Send !g                     ; select the Category menu
      Send w                      ; select the Window category
      Send {Right}                ; expand the category
      Send a                      ; select the Appearance subcategory
      ControlClick, ClassNN Button8, ahk_class PuTTYConfigBox, , Left, 1
    }
  #IfWinActive
  </code></pre>
  
  <p>When run from a PuTTY terminal window, everything up through "Send a" navigates the PuTTY menus as expected, bringing me to the Appearance subcategory. At this point I want to click the "Change..." button to set the font. I'd prefer not to send a bunch of tabs or specify a screen coordinate to select the button; as that seems kludgey and likely to break with future updates. I can't get ControlClick to work, though. The line I used above is my best guess after a couple hours of research, and I can't see why it does nothing.</p>
  
  <p>Here's the Window Spy output when I'm hovering over the button:</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;
  PuTTY Reconfiguration
  ahk_class PuTTYConfigBox
  
  &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:  1051, 207  (less often used)
  In Active Window:   432, 202
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Now Under Mouse Cursor )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  ClassNN:    Button8
  Text:   Change...
  Color:  0xF0F0F0  (Blue=F0 Green=F0 Red=F0)
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Active Window Position )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  left: 619     top: 5     width: 456     height: 438
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Status Bar Text )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Visible Window Text )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  &amp;Apply
  &amp;Cancel
  Cate&amp;gory:
  Cursor appearance:
  B&amp;lock
  &amp;Underline
  &amp;Vertical line
  Cursor &amp;blinks
  Adjust the use of the cursor
  Fo&amp;nt used in the terminal window
  Font: Lucida Console, 24-point
  Change...
  Allow selection of variable-pitch fonts
  Font &amp;quality:
  Antialiased
  Non-Antialiased
  ClearType
  Default
  Font settings
  Hide mouse &amp;pointer when typing in window
  Adjust the use of the mouse pointer
  Gap b&amp;etween text and window edge:
  &amp;Sunken-edge border (slightly thicker)
  Adjust the window border
  
  &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;( Hidden Window Text )&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  
  &gt;&gt;&gt;&gt;( TitleMatchMode=slow Visible Text )&lt;&lt;&lt;&lt;
  1
  
  &gt;&gt;&gt;&gt;( TitleMatchMode=slow Hidden Text )&lt;&lt;&lt;&lt;
  </code></pre>
  
  <p>Thanks for your help.</p>