title: Send keystrokes to a specific window (in background), but do something else in the meantime
body: <p>This code (inspired from <a href="https://stackoverflow.com/questions/2791839/which-is-the-easiest-way-to-simulate-keyboard-and-mouse-on-python">Which is the easiest way to simulate keyboard and mouse on Python?</a>) opens a Notepad and send the keys A, B, C, D, ..., Z every second:</p>
  
  <pre><code>import win32com.client, time
  shell = win32com.client.Dispatch("WScript.Shell")
  shell.Run('Notepad')
  time.sleep(1)
  shell.AppActivate("Notepad")
  for i in range(65,91):
      shell.SendKeys(chr(i))
      time.sleep(1)
  </code></pre>
  
  <p>I would like to let this operation continue in background, continue my work on the computer, <strong>and have the keystrokes sent to Notepad (in background)</strong>.</p>
  
  <p>Problem: if I open another application (example: browser) in the meantime, the keystrokes are sent ... to the currently active window, which I dont't want!</p>
  
  <p><strong>Question: how to have Python send the keystrokes to notepad.exe <em>only</em>, even if this application is not in foreground?</strong></p>
  
  <p>Context: I'm automating some long task requiring that my Python script sends keystrokes to <code>app.exe</code> (in background) during maybe 15 minutes,  but I'd like to do something else with the computer in the meantime.</p>
  
  <p>Note: More generally, the use case I'm interested in is the case where the process app.exe might open dialogs, close dialogs, open other windows, so the solution should be able to send the keystrokes to the <em>active window of the process</em>. Thus a solution with a fixed hWnd like <a href="https://stackoverflow.com/a/38888131">here</a> doesn't work directly.</p>