Skip to main content

方便地阅读或模拟游戏手柄

项目描述

游戏Pyd

玩电子游戏很有趣不是吗?那么为什么让 Python 玩游戏有什么不同呢?至少应该很容易!肯定吗?这就是这个图书馆的用途。gamePyd 为常见用例提供现成的方法。它还为您提供了它使用的积木,使在 Windows 上读取和模拟 xbox 控制器变得轻而易举。

在底层,ScpVBusnefarius被封装以与 XInput 交互,而 XInput 又被封装在方法中,让您使用首选数据结构并无缝使用转换后的信息来控制游戏手柄。目前我们支持数据框、列表和字典。

先决条件

该库应该适用于 Python 3.6 之后的任何内容,尽管仅在 3.8.4 及更高版本上进行了测试。目前唯一支持的操作系统是 Windows 10。

要使用虚拟控制器对象,您需要ScpVBus. 为方便起见,它的一个版本包含在这个项目中。更多关于原件的信息可以在nefarius 的存档仓库中找到。您可能还需要x360ce来简化与游戏的连接以及调试它。我已经包含了它的旧版本,因为它对我有用。

安装 ScpVbus

我们需要 ScpVBus 与 Windows 讨论游戏手柄相关的详细信息:在 ScpVBus-x64 目录中打开提升的 cmd 命令提示符并运行devcon.exe install ScpVBus.inf Root\ScpVBus. 成功运行由以下消息指示:

Device node created. Install is complete when drivers are installed...
Updating drivers for Root\ScpVBus from {Location}\PYXInput\ScpVBus-x64\ScpVBus.inf.
Drivers installed successfully.

安装

现在基础知识已经完成,我们应该通过通常的动作:

通过 pip 安装

pip install gamePyd

你赶时间吗?

两个主要模块:

  • writePadwPad包含用于控制(最多 4 个)虚拟游戏手柄的对象 [ ]
    • 使用该playMoment方法分配作为字典传入的状态
    • 或将行作为状态的数据框传递给playback.
  • 要读取游戏手柄(虚拟或物理),请使用readPadrPad中的对象
    • record将以给定的速率在固定的时间内读取控制器,并返回一个数据帧。
    • capture将执行相同的操作,但仅在检测到控制器上的指定按钮按下时终止。

如果您不着急,请前往wiki 页面。如果您想请求任何功能,请提出问题。

测试控制器的读数

运行test_read()应该给出(下面的输出是没有插入控制器时):

Testing controller in position 1:
This will just take a second. We'll look at the controller values in 200 milli-second intervals:
0---------------------------------------------
State:{'LT': 0, 'RT': 0, 'Lx': 0, 'Ly': 0, 'Rx': 0, 'Ry': 0, 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'START': False, 'SELECT': False, 'L3': False, 'R3': False, 'LB': False, 'RB': False, 'A': False, 'B': False, 'X': False,
 'Y': False}
---------------------------------------------
1---------------------------------------------
State:{'LT': 0, 'RT': 0, 'Lx': 0, 'Ly': 0, 'Rx': 0, 'Ry': 0, 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'START': False, 'SELECT': False, 'L3': False, 'R3': False, 'LB': False, 'RB': False, 'A': False, 'B': False, 'X': False,
 'Y': False}
---------------------------------------------
2---------------------------------------------
State:{'LT': 0, 'RT': 0, 'Lx': 0, 'Ly': 0, 'Rx': 0, 'Ry': 0, 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'START': False, 'SELECT': False, 'L3': False, 'R3': False, 'LB': False, 'RB': False, 'A': False, 'B': False, 'X': False,
 'Y': False}
---------------------------------------------
3---------------------------------------------
State:{'LT': 0, 'RT': 0, 'Lx': 0, 'Ly': 0, 'Rx': 0, 'Ry': 0, 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'START': False, 'SELECT': False, 'L3': False, 'R3': False, 'LB': False, 'RB': False, 'A': False, 'B': False, 'X': False,
 'Y': False}
---------------------------------------------
4---------------------------------------------
State:{'LT': 0, 'RT': 0, 'Lx': 0, 'Ly': 0, 'Rx': 0, 'Ry': 0, 'UP': False, 'DOWN': False, 'LEFT': False, 'RIGHT': False, 'START': False, 'SELECT': False, 'L3': False, 'R3': False, 'LB': False, 'RB': False, 'A': False, 'B': False, 'X': False,
 'Y': False}
---------------------------------------------
Better yet, you can use prettyRead() to sample as many times as desired for any required duration.
And then return it as a dataframe, can even write it to a file by supplying the filename.
    LT  RT  Lx  Ly  Rx  Ry     UP   DOWN   LEFT  RIGHT  START  SELECT     L3     R3     LB     RB      A      B      X      Y             time(ns)  timeDelta(ms)  error(ms)
0   0   0   0   0   0   0  False  False  False  False  False   False  False  False  False  False  False  False  False  False  1605620332292776700         9.9744   1.641067
1   0   0   0   0   0   0  False  False  False  False  False   False  False  False  False  False  False  False  False  False  1605620332301749900         8.9732   0.639867
2   0   0   0   0   0   0  False  False  False  False  False   False  False  False  False  False  False  False  False  False  1605620332310727300         8.9774   0.644067
3   0   0   0   0   0   0  False  False  False  False  False   False  False  False  False  False  False  False  False  False  1605620332319701900         8.9746   0.641267
4   0   0   0   0   0   0  False  False  False  False  False   False  False  False  False  False  False  False  False  False  1605620332328678100         8.9762   0.642867
Do note that the final three columns are metadata.

路线图

下面列出了即将推出的显着功能(更多详细信息在随附的项目中):

  • 校准机器与机器之间的速度差异,从而自动最小化读取速率的偏差。
  • 写入游戏手柄时检查延迟
  • 添加单元测试
  • 展开维基

学分

另请参阅参与 PYXinput的贡献者列表(该项目从中分叉)。

致谢

项目详情


下载文件

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

源分布

gamePyd-0.1.0.tar.gz (2.0 MB 查看哈希

已上传 source

内置分布

gamePyd-0.1.0-py3-none-any.whl (1.3 MB 查看哈希

已上传 py3