Skip to main content

使用直接输入的 Windows 的 Python 鼠标和键盘输入自动化。

项目描述

PyDirectInput

该库旨在复制 PyAutoGUI 鼠标和键盘输入的功能,但通过使用 DirectInput 扫描代码和更现代的 SendInput() win32 函数。PyAutoGUI 使用虚拟键代码 (VK) 和已弃用的 mouse_event() 和 keybd_event() win32 函数。您可能会发现 PyAutoGUI 在某些应用程序中不起作用,尤其是在视频游戏和其他依赖 DirectX 的软件中。如果您发现自己处于这种情况,请尝试使用此库!

pip install pydirectinput

该软件包旨在与 PyAutoGUI 结合使用。您可以继续使用 PyAutoGUI 的所有酷功能,只需在 PyDirectInput 中替换不起作用的输入即可。功能接口相同,但此包可能未实现所有可选参数和功能。

想查看实现的缺失功能吗?为什么不自己尝试一下!我欢迎所有拉取请求,并很乐意与您合作以充实解决方案。参与开源!了解有关编程的更多信息!垫你的简历!玩得开心!

源代码在https://github.com/learncodebygaming/pydirectinput

在此处观看教程:即将推出

示例用法

    >>> import pyautogui
    >>> import pydirectinput
    >>> pydirectinput.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.
    >>> pydirectinput.click() # Click the mouse at its current location.
    >>> pydirectinput.click(200, 220) # Click the mouse at the x, y coordinates 200, 220.
    >>> pydirectinput.move(None, 10)  # Move mouse 10 pixels down, that is, move the mouse relative to its current position.
    >>> pydirectinput.doubleClick() # Double click the mouse at the
    >>> pydirectinput.press('esc') # Simulate pressing the Escape key.
    >>> pydirectinput.keyDown('shift')
    >>> pydirectinput.keyUp('shift')

文档

可以通过以下文档中的面包屑找到 DirectInput 键代码:https ://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-input

您可能还对这里的主要 SendInput 文档感兴趣:https ://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput

您可以在此处找到有关在视频游戏中使用 vkCodes 的问题的讨论:https ://stackoverflow.com/questions/14489013/simulate-python-keypresses-for-controlling-a-game

测试

要运行提供的测试:首先设置一个 virtualenv。然后,您可以通过执行 pip 在可编辑状态下安装此项目pip install -e .。这允许您在运行测试时反映您对这些项目文件所做的任何编辑。使用python3 tests.

我一直在用半条命 2 进行测试,以确认这些输入适用于 DirectX 游戏。

实现的功能

  • 不通过安全检查
  • 暂停
  • 位置()
  • 尺寸()
  • 移动到(x,y)
  • 移动(x,y)/moveRel(x,y)
  • 鼠标按下()
  • 鼠标向上()
  • 点击()
  • 键下()
  • 键向上()
  • 按()
  • 写()/打字()

未实现的功能

  • 滚动功能
  • 拖动功能
  • 热键功能
  • 支持需要 shift 键的特殊字符(即'!'、'@'、'#'...)
  • 鼠标功能上忽略的参数:持续时间、补间、logScreenshot
  • 键盘功能上的忽略参数:logScreenshot

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

PyDirectInput-1.0.4.tar.gz (7.5 kB 查看哈希

已上传 source

内置分布

PyDirectInput-1.0.4-py3-none-any.whl (8.9 kB 查看哈希

已上传 py3