I'm trying to press a key in another process from a Python program. I've tried the win32 api, but somehow this code does nothing:
import win32gui
import win32con
import win32api
hwnd = win32gui.FindWindow("notepad", "prueba.txt: Bloc de notas")
if(hwnd != 0):
win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
win32api.SendMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
while(True):
win32api.SendMessage(
hwnd,
win32con.WM_CHAR,
ord('x'),
0)
else:
print("The window is closed")
Of course I want to do this to an inactive window. Any solution or alternatives?
Thanks