title: How to send a keystroke to an other process (ex a notepad)?
body: <p>I got a notepad which has a PID: 2860<br></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;psapi.h&gt;
  using namespace std;
  HWND SendIt (DWORD dwProcessID){
      HWND hwnd = NULL;
      do {
           hwnd = FindWindowEx(NULL, hwnd, NULL, NULL);
           DWORD dwPID = 0;
           GetWindowThreadProcessId(hwnd, &amp;dwPID);
           if (dwPID == dwProcessID) {
              cout&lt;&lt;"yay:"&lt;&lt;hwnd&lt;&lt;":pid:"&lt;&lt;dwPID&lt;&lt;endl;//debug
              PostMessage(hwnd,WM_KEYDOWN,'A',1); //send
           }
      } while (hwnd != 0);
      return hwnd; //Ignore that
  
  }
  int main()
  {
      SendIt(2680); //notepad ID
      return 0;
  }
  </code></pre>
  
  <p>and notepad should write <code>A</code> to it but nothing happens.<br>
  I tried <code>WM_DESTROY</code> message on it and it's working but <code>WM_KEYDOWN</code> is not working.<br>
  I have also done <code>GetLastError()</code> and it prints error 2 <code>ERROR_FILE_NOT_FOUND</code>.<br><br></p>
  
  <p>Why is this not working and is it possible to fix it? </p>