Try using this, it manages to work for me send the keystrokes to the inactive window,
Use (but add error checking) hwndMain = win32gui.FindWindow("notepad", "​prueba.txt: log keys") hwndEdit = win32gui.FindWindowEx
I would like to send DirectInput keys to an inactive window without interfering with my actual mouse. I tried using PostMessage, SendInput and SendMessage but pywin32 uses virtual keycodes while ctypes does work with DirectInput. I have no idea how I can make it send in an inactive window.
How to send DirectInput keys to an inactive window in Python