I am trying to make a program that will send key events to multiple windows at the same time. Note: the windows I am trying to send key events to are games
I managed to use win32api.PostMessage, but that can't hold the key down + it doesn't work for games. PostMessage works for notepad windows, but not for games.
I am using python with win32 modules but any other modules are welcome.
Here is what I have:
def on_press_forward(key):
for instance in game_instances:
hwndChild = win32gui.GetWindow(instance, win32con.GW_CHILD)
letter = get_key_code(key)
if not letter == 0:
temp = win32api.PostMessage(hwndChild, win32con.WM_CHAR, int(letter, 16), 0)
The function above is automatically called when a key is pressed. The key variable is a pynput object. game_instances is a list with hwnd of all game windows. get_key_code returns a hex value that corresponds to the letter provided ( because PostMessage requires it to be in hex ), or returns 0 if the key in not a letter ( for ex. shift ).
What other function to use except PostMessage? Thanks for any help!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…