Python3在DirectX游戏中移动鼠标 [英] Python3 move mouse in DirectX games

查看:789
本文介绍了Python3在DirectX游戏中移动鼠标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个脚本,以在DirectX游戏中执行一些操作。



我已经完成了移动鼠标的所有工作。 / p>

有没有可用的模块可以移动鼠标,适用于Windows(Python 3)



谢谢!

p>

解决方案

我使用了 pynput 在Python 2.7中使用过一次。我刚刚在Python 3.7下进行了检查,它可以很好地移动光标。来自链接源的示例代码:

 来自pynput.mouse import按钮,控制器

鼠标=控制器( )

#读取指针位置
print('当前指针位置为{0}'。format(
mouse.position))

#设置指针位置
mouse.position =(10,20)
print('现在我们将其移至{0}'。format(
mouse.position))

#相对于当前位置移动指针
mouse.move(5,-5)

#按下并释放
mouse.press(Button.left)
mouse.release(Button.left)

#双击;这与在Mac OSX上按下并释放
#两次不同。
mouse.click(Button.left,2)

#向下滚动两步
mouse.scroll (0,2)

编辑:刚刚在DirectX游戏中成功测试。


I'm trying to build create a script that does a few action inside an DirectX game.

I've got everything working exept for moving the mouse.

Is there any module avalable that can move the mouse, for windows (python 3)

Thanks!

解决方案

I used pynput once in Python 2.7. I just checked under Python 3.7 and it moves the cursor alright. Sample code from linked source:

from pynput.mouse import Button, Controller

mouse = Controller()

# Read pointer position
print('The current pointer position is {0}'.format(
    mouse.position))

# Set pointer position
mouse.position = (10, 20)
print('Now we have moved it to {0}'.format(
    mouse.position))

# Move pointer relative to current position
mouse.move(5, -5)

# Press and release
mouse.press(Button.left)
mouse.release(Button.left)

# Double click; this is different from pressing and releasing
# twice on Mac OSX
mouse.click(Button.left, 2)

# Scroll two steps down
mouse.scroll(0, 2)

Edit: Just successfully tested in a DirectX game.

这篇关于Python3在DirectX游戏中移动鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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