win32gui.FindWindow Not finding window
<p>I'm trying to send a keystroke to an inactive TeraTerm Window using Pywin32. </p>

<p><a href="https://stackoverflow.com/a/38888131/3714940">This</a> answer led me to write this code:</p>

<pre><code>import win32gui
import win32con
import win32api

hwndMain = win32gui.FindWindow("Tera Term VT", None)
print hwndMain
hwndChild = win32gui.GetWindow(hwndMain, win32con.GW_CHILD)
win32api.PostMessage(hwndChild, win32con.WM_CHAR, 0x5b, 0)
</code></pre>

<p>but:<br>
<code>hwndMain = win32gui.FindWindow("Tera Term VT", None)</code> returns <code>0</code>, it can't find the window. </p>

<p>If I change <code>"Tera Term VT"</code> to <code>"Notepad"</code>, I can happily send keystrokes to an active Notepad window all day long. So, why can't I  get the TeraTerm window?</p>

<p>According to the <a href="http://docs.activestate.com/activepython/2.7/pywin32/win32gui__FindWindow_meth.html" rel="noreferrer">ActiveState documentation</a>:</p>

<blockquote>
  <p>PyHANDLE = FindWindow(ClassName, WindowName)</p>
  
  <p>ClassName : PyResourceId
  Name or atom of window class to find, can be None<br>
  WindowName : string
  Title of window to find, can be None</p>
</blockquote>

<p>So how can I get the correct ClassName to use?</p>

<p>I've tried just about every variation of <code>Tera Term VT</code>, escaping the spaces: <code>"Tera\ Term\ VT"</code>, enclosing the whole in single quotes: <code>"'Tera Term VT'"</code>, but nothing works. I've even tried using the name of the process:<code>"ttermpro.exe"</code>, and included the child name in the string <code>"COM11:115200baud - Tera Term VT"</code> in my desperation, but nothing works.</p>

<p>Interestingly,  this:</p>

<pre><code>import win32com.client

shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Tera Term VT")
shell.SendKeys("\%i", 0)
</code></pre>

<p>works just fine, but brings the window to the foreground, which I don't wan't. The <code>Tera Term VT</code> string works fine in this instance though.</p>