Skip to main content

Read or emulate gamepads conviniently

Project description

gamePyd

Playing video games is fun isn't it? So why should making Python play games be any different ? It should at least be easy! surely ? That's what this library here is for. gamePyd provides readymade methods for common use cases. It also gives you the bricks it used as well, making reading and emulating xbox controllers trivial on Windows.

Under the hood, nefarius's ScpVBus is wrapped to interact with XInput, which is in turn wrapped in methods to let you work with your preffered data structure and seamlessly use the transformed information to control gamepads. Currently we support dataframes, lists and dictionaries.

Prerequisites

This library should work with anything after Python 3.6, albeit testing has only been done on 3.8.4 and later. Currently the only supported OS is Windows 10.

To use the Virtual Controller object, you need ScpVBus. For ease one of it's versions is included in this project. More information about the original can be found at nefarius's archived repo. You'll probably also require x360ce for easing the connection to games as well as debugging it. I've included it's older version as that's the one that worked for me.

Installing ScpVbus

We need ScpVBus to talk to Windows about gamepad related details: Open an elevated cmd command prompt in the ScpVBus-x64 directory and run devcon.exe install ScpVBus.inf Root\ScpVBus. Successful run is indicated by the following message:

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.

Installing

Now that the basics are done, we ought to go throught the usual motions:

Install via pip

pip install gamePyd

Are you in a rush?

Two main modules:

  • writePad contains object [wPad] which you use to control (upto 4) virtual game pads
    • use the playMoment method to assign a state passed in as a dictionary
    • or pass in a dataframe with rows as states to playback.
  • To read gamepads(virtual or physical), you use the rPad object in readPad
    • record will read the controller at a given rate for a fixed duration, and return a dataframe.
    • capture will do the same, but instead terminate only on detecting a specified button press on the controller.

If you're not in a rush, please head to the wiki pages. If you'd like to request any features please raise an issue.

Test the reading of controllers

Running test_read() should give (the output below was when no controller was plugged-in):

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.

Roadmap

Salient upcoming features are listed below (more details in the accompanying project):

  • Calibration for machine-to-machine speed differences, so as to automatically minimize deviation from reading rate.
  • Check for lag while writing to gamepads
  • Add unit tests
  • Expand the wiki

Credits

See also the list of contributors who participated in PYXinput (from which this project was forked).

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gamePyd-0.1.0.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gamePyd-0.1.0-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file gamePyd-0.1.0.tar.gz.

File metadata

  • Download URL: gamePyd-0.1.0.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

File hashes

Hashes for gamePyd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14acaa07d8746b6428bb15bd817ff009161ca6e7ceed3a76faff264dab3778b1
MD5 6092d5189034a18f11441b42f201bec8
BLAKE2b-256 67a064b61d6f3dd5035249ea17bd8a73d3782f5332a4be7eb777c07d0e72efa8

See more details on using hashes here.

File details

Details for the file gamePyd-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gamePyd-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0

File hashes

Hashes for gamePyd-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6d8f669691b67c16133d9f2d06aae653d5c4818a016de2d2b8e007b9c0e7c1a
MD5 6322f5ccbb267e176e91a5edbad7b255
BLAKE2b-256 8c8256096f4d447eb718e85373e1147291ade140d6a10fd524ab661e1ebbb011

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page