Pyautogui在游戏窗口中不起作用 [英] Pyautogui don't work in game window

查看:6152
本文介绍了Pyautogui在游戏窗口中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Pyautogui在游戏上进行一些测试. 但是在那些会更改光标和全屏游戏的游戏中,没有一种方法有效.

I'm making some tests using Pyautogui on games. But in those games that change your cursor and fullscreen games, none of the methods work.

我现在正在网上尝试《仙境传说》.

I'm trying now on Ragnarok Online.

我尝试过:

pyautogui.click()
pyautogui.moveTo(x, y, time)
pyautogui.moveRel(x, y)

在游戏窗口中时,它们都不起作用.他们在外面工作正常.

None of them works when inside the game window. They work fine outside.

有没有办法使它起作用?还是我可以使用的另一个库?

Is there a way to make it work? Or another library that I could use?

顺便说一句,win32api.SetCursorPos((x,y))也不起作用.

By the way, win32api.SetCursorPos((x,y)) also doesn't work.

谢谢.

推荐答案

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)

这是一个win32API,内部调用了SendInput.

and it's a win32API which called SendInput internally.

SendInput函数会将输入事件插入到与硬件设备相同的队列中,但是这些事件用LLMHF_INJECTED标志标记,该标志可由钩子检测.为了避免此标志,您可能必须编写一个自定义驱动程序.

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游戏中模拟键盘有很多答案和问题,有人说可以,有人说不能.而且,您可以尝试一个可以回答的答案

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

,但我认为游戏必须使用Directx接口与硬件进行通信以提高速度,然后SendInput仅将事件插入消息队列中.而您想使用SendInputMouse_Event.说,

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.

如何? VMware.完成了.

How? VMware. It's done.

这篇关于Pyautogui在游戏窗口中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆