title: C# SendKeys to foreground window in Windows 7 not working
body: <p>I'm trying to build a global hotkey application with C# in Visual Studio 2012 to run on Windows 7.  I have everything working except the SendKeys are never showing in the application.</p>
  
  <p>Here is the code I am using to send the keystrokes:</p>
  
  <p><strong>Updated</strong> to debug with <code>GetFocusedWindow</code> example.</p>
  
  <pre><code>StringBuilder className = new StringBuilder(256);
  IntPtr hWnd = GetForegroundWindow();
  GetClassName(hWnd, className, className.Capacity);
  Debug.WriteLine("Foreground window: {0}={1}", hWnd.ToInt32().ToString("X"), className);
  hWnd = GetFocusedWindow();
  GetClassName(hWnd, className, className.Capacity);
  Debug.WriteLine("Focused window: {0}={1}", hWnd.ToInt32().ToString("X"), className);
  
  SendKeys.Send("Hello World");
  </code></pre>
  
  <p>When I debug the program, focus Notepad, and hit the hotkey I get the following debug message and the keystrokes are never inserted into Notepad:</p>
  
  <pre><code>Foreground Window: 4F02B6=Notepad
  Focused Window: 1B6026A=WindowsForms10.Window.8.app.0.bf7d44_r11_ad1
  </code></pre>
  
  <p>How can I send keystrokes to the current foreground window?</p>