Pyautogui 在游戏中不起作用 window
Pyautogui don't work in game window
我正在对游戏使用 Pyautogui 进行一些测试。
但是在那些改变你的光标的游戏和全屏游戏中,none 的方法是有效的。
我正在试玩 Ragnarok Online。
我试过了:
pyautogui.click()
pyautogui.moveTo(x, y, time)
pyautogui.moveRel(x, y)
None 个在游戏中有效 window。他们在外面工作得很好。
有没有办法让它发挥作用?或者我可以使用的另一个库?
顺便说一下,win32api.SetCursorPos((x,y))
也行不通。
谢谢。
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)
这是一个在内部调用 SendInput
的 win32API。
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.
关于如何在DirectX游戏中模拟键盘有很多答案和问题,有人说可以,有人说不能。而且,你可以试试这个 an answer which say could
但在我看来,游戏必须使用 directx 接口与硬件通信以提高速度,然后 SendInput
仅将事件插入消息 queue.and 你想使用 SendInput
或Mouse_Event
。俗话说,
There's no problem that can't be solved with another level of indirection
让我们为游戏添加一个消息队列。
怎么样?威睿。完成了。
此问题已通过 pydirectinput library: https://learncodebygaming.com/blog/pyautogui-not-working-use-directinput
解决
pip install pydirectinput
然后替换代码中的导入:
import pytautogui
import pydirectinput
替换从 pyautogui
到 pydirectinput
的每个函数调用,您就完成了。
我正在对游戏使用 Pyautogui 进行一些测试。 但是在那些改变你的光标的游戏和全屏游戏中,none 的方法是有效的。
我正在试玩 Ragnarok Online。
我试过了:
pyautogui.click()
pyautogui.moveTo(x, y, time)
pyautogui.moveRel(x, y)
None 个在游戏中有效 window。他们在外面工作得很好。
有没有办法让它发挥作用?或者我可以使用的另一个库?
顺便说一下,win32api.SetCursorPos((x,y))
也行不通。
谢谢。
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)
这是一个在内部调用 SendInput
的 win32API。
The
SendInput
function will insert input events into the same queue as a hardware device but the events are marked with aLLMHF_INJECTED
flag that can be detected by hooks. To avoid this flag you probably have to write a custom driver.
关于如何在DirectX游戏中模拟键盘有很多答案和问题,有人说可以,有人说不能。而且,你可以试试这个 an answer which say could
但在我看来,游戏必须使用 directx 接口与硬件通信以提高速度,然后 SendInput
仅将事件插入消息 queue.and 你想使用 SendInput
或Mouse_Event
。俗话说,
There's no problem that can't be solved with another level of indirection
让我们为游戏添加一个消息队列。
怎么样?威睿。完成了。
此问题已通过 pydirectinput library: https://learncodebygaming.com/blog/pyautogui-not-working-use-directinput
解决pip install pydirectinput
然后替换代码中的导入:
import pytautogui
import pydirectinput
替换从 pyautogui
到 pydirectinput
的每个函数调用,您就完成了。