title: Autohotkey Simple ControlSend to Google Chrome
body: <p><strong>EDIT for working version</strong></p>
  
  <pre><code>!j::
  SetTitleMatchMode, 2
  
  ControlGet, OutputVar, Hwnd,,Chrome_RenderWidgetHostHWND1, Google Chrome
  
  ControlFocus,,ahk_id %outputvar%
  
  
  ControlSend, , {Space} , Google Chrome
  </code></pre>
  
  <p>Original post:</p>
  
  <pre><code>DetectHiddenWindows, on
  !j::
  IfWinExist, ahk_exe chrome.exe
  ControlSend, ahk_exe chrome.exe, {SPACE}
  return
  </code></pre>
  
  <p>What I want is to be able to toggle Play/Pause on a youtube video that is playing through chrome. The chrome window is not the active window, but is showing on my second monitor. I've tried using the ahk_class Chrome_WidgetWin_1 from WindowSpy and also doing a ControlClick with the ClassNN: Chrome_RenderWidgetHostHWND1 but nothing seems to properly send a {SPACE} or CLICK to pause the video.</p>
  
  <p>WindowSpy info (the video title will not be consistent):</p>
  
  <pre><code>Calculus 2 Lecture 10.2: Introduction to Parametric Equations - YouTube - Google Chrome
  ahk_class Chrome_WidgetWin_1
  ahk_exe chrome.exe
  
  Absolute:   -908, 634 (less often used)
  Relative:   1012, 634 (default)
  Client: 1012, 634 (recommended)
  
  ClassNN:    Intermediate D3D Window1
  Text:   
  Color:  05070D (Red=05 Green=07 Blue=0D)
      x: 0    y: 0    w: 1920 h: 1080
  Client: x: 0    y: 0    w: 1920 h: 1080
  
  Chrome Legacy Window
  Chrome Legacy Window
  
  Chrome Legacy Window
  Chrome Legacy Window
  </code></pre>