I know that this question is asked many times but none of these solutions solved my problem.
I managed to create a code that presses text edit controllers but for games, it doesn’t work.
here is my code that works for any text edit controller:
import win32gui, win32con, win32api
def get_inner_windows(whndl):
hwnds = set()
def callback(hwnd, param):
nonlocal hwnds
if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
hwnds.add(hwnd)
win32gui.EnumChildWindows(hwnd, callback, None)
return True
hwnds.add(whndl)
win32gui.EnumChildWindows(whndl, callback, None)
return hwnds
hwnd= win32gui.FindWindow(None, "Untitled - Notepad")
hwnds = get_inner_windows(hwnd)
for hwnd in hwnds:
win32api.SendMessage(hwnd, win32con.WM_CHAR, ord('A'),0)
If I use this code in games all the keyboard presses happen only in the text edits on this game.
Any update regarding this matter?