title: How to send a key to another application
body: <p>I want to send a specific key (e.g. k) to another program named notepad, and below is the code that I used:</p>
  <pre><code>private void SendKey()
  {
      [DllImport (&quot;User32.dll&quot;)]
      static extern int SetForegroundWindow(IntPtr point);
  
      var p = Process.GetProcessesByName(&quot;notepad&quot;)[0];
      var pointer = p.Handle;
  
      SetForegroundWindow(pointer);
      SendKeys.Send(&quot;k&quot;);
  }
              
  </code></pre>
  <p>But the code doesn't work, what's wrong with the code?</p>
  <p>Is it possible that I send the &quot;K&quot; to the notepad without notepad to be the active window? (e.g. active window = &quot;Google chrome&quot;, notepad is in the background, which means sending a key to a background application)?</p>