Pyautogui don't work in game window

不想你离开。 提交于 2019-12-05 17:52:30
obgnaw

The source code of Pyautogui

def _sendMouseEvent(ev, x, y, dwData=0):
    assert x != None and y != None, 'x and y cannot be set to None'
    width, height = _size()
    convertedX = 65536 * x // width + 1
    convertedY = 65536 * y // height + 1
    ctypes.windll.user32.mouse_event(ev, ctypes.c_long(convertedX), ctypes.c_long(convertedY), dwData, 0)

and it's a win32API which called SendInput internally.

The SendInput function will insert input events into the same queue as a hardware device but the events are marked with a LLMHF_INJECTED flag that can be detected by hooks. To avoid this flag you probably have to write a custom driver.

There are plenty of answer and question about how to simulate keyboard in DirectX game which some say could and some say could not. And, you may try this an answer which say could

but in my opinion,must game use directx interface to communicate with the hardware for speed,then the SendInput only insert events into the message queue.and you want to use SendInput or Mouse_Event.So as the saying,

There's no problem that can't be solved with another level of indirection

let's add a message queue for the game.

How? VMware. It's done.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!