Send Keys To A Inactive Window In Python
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 h
Solution 1:
Use (but add error checking)
hwndMain = win32gui.FindWindow("notepad", "prueba.txt: Bloc de notas")
hwndEdit = win32gui.FindWindowEx( hwndMain, 0, "Edit", 0 )
win32api.PostMessage( hwndEdit,win32con.WM_CHAR, ord('x'), 0)
you should add some "sleep" calls if you want to loop posting message :-)
Solution 2:
The target window is wrong. Notepad has more than 1 window: it has a frame window with child edit control. To make your code work you should find a child of frame (= hwnd in your code) that is an edit control and send WM_CHARs to it.
Post a Comment for "Send Keys To A Inactive Window In Python"