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.