Skip to main content

pyvjoystick

pyvjoystick is a set of python binding for different virtual devices. Currently vJoy and ViGEm are supported.

vJoy(on github from jshafer817 and njz3). The implementation of vjoy bindings are inspired on pyvjoy's package.

ViGEm bindings are inspired on vgamepad's package.

Requirements

To be able to use vJoy device install vJoy from sourceforge or github. It is recommended to also install the vJoy Monitor and Configure vJoy programs. These should be an option during installation.

To be able to use ViGem device install release. This package ships with a ViGemClient binaries.

Installation

Simple! This package is installable by pip

pip install pyvjoystick

Usage

vJoy example

With this library you can easily set Axis and Button values on any vJoy device. Low-level bindings are provided in pyvjoy._sdk.

import pyvjoystick.vjoy as vjoy

# Pythonic API, item-at-a-time
j = vjoy.VJoyDevice(1)

# turn button number 15 on
j.set_button(15, 1)

# Notice the args are (buttonID,state) whereas vJoy's native API is the other way around.


# turn button 15 off again
j.set_button(15, 0)

# Set X axis to fully left
j.set_axis(vjoy.HID_USAGE.X, 0x1)

# Set X axis to fully right
j.set_axis(vjoy.HID_USAGE.X, 0x8000)

# Also implemented:

j.reset()
j.reset_buttons()
j.reset_povs()


# The 'efficient' method as described in vJoy's docs - set multiple values at once

print(j._data)
# >> > <pyvjoystick.vjoy._sdk._JOYSTICK_POSITION_V2 at 0x.... >


j._data.lButtons = 19  # buttons number 1,2 and 5 (1+2+16)
j._data.wAxisX = 0x2000
j._data.wAxisY = 0x7500

# send data to vJoy device
j.update()


# Lower-level API just wraps the functions in the DLL as thinly as possible, with some attempt to raise exceptions instead of return codes.

XBox360 gamepad

The following python script creates a virtual XBox360 gamepad:

import pyvjoystick.vigem as vg

gamepad = vg.VX360Gamepad()

As soon as the VX360Gamepad object is created, the virtual gamepad is connected to your system via the ViGEmBus driver, and will remain connected until the object is destroyed.

Buttons can be pressed and released through press_button and release_button:

gamepad.press_button(button=vg.XUSB_BUTTON.XUSB_GAMEPAD_A)  # press the A button
gamepad.press_button(button=vg.XUSB_BUTTON.XUSB_GAMEPAD_DPAD_LEFT)  # press the left hat button

gamepad.update()  # send the updated state to the computer

# (...) A and left hat are pressed...

gamepad.release_button(button=vg.XUSB_BUTTON.XUSB_GAMEPAD_A)  # release the A button

gamepad.update()  # send the updated state to the computer

# (...) left hat is still pressed...

All available buttons are defined in XUSB_BUTTON

To control the triggers (1 axis each) and the joysticks (2 axis each), two options are provided by the API.

It is possible to input raw integer values directly:

gamepad.left_trigger(value=100)  # value between 0 and 255
gamepad.right_trigger(value=255)  # value between 0 and 255
gamepad.left_joystick(x_value=-10000, y_value=0)  # values between -32768 and 32767
gamepad.right_joystick(x_value=-32768, y_value=15000)  # values between -32768 and 32767

gamepad.update()

Or to input float values:

gamepad.left_trigger_float(value_float=0.5)  # value between 0.0 and 1.0
gamepad.right_trigger_float(value_float=1.0)  # value between 0.0 and 1.0
gamepad.left_joystick_float(x_value_float=-0.5, y_value_float=0.0)  # values between -1.0 and 1.0
gamepad.right_joystick_float(x_value_float=-1.0, y_value_float=0.8)  # values between -1.0 and 1.0

gamepad.update()

Reset to default state:

gamepad.reset()

gamepad.update()

DualShock4 gamepad

Using a virtual DS4 gamepad is similar to X360:

import pyvjoystick.vigem as vg

gamepad = vg.VDS4Gamepad()

Press and release buttons:

gamepad.press_button(button=vg.DS4_BUTTONS.DS4_BUTTON_TRIANGLE)
gamepad.update()

# (...)

gamepad.release_button(button=vg.DS4_BUTTONS.DS4_BUTTON_TRIANGLE)
gamepad.update()

Available buttons are defined in DS4_BUTTONS

Press and release special buttons:

gamepad.press_special_button(special_button=vg.DS4_SPECIAL_BUTTONS.DS4_SPECIAL_BUTTON_PS)
gamepad.update()

# (...)

gamepad.release_special_button(special_button=vg.DS4_SPECIAL_BUTTONS.DS4_SPECIAL_BUTTON_PS)
gamepad.update()

Special buttons are defined in DS4_SPECIAL_BUTTONS

Triggers and joysticks (integer values):

gamepad.left_trigger(value=100)  # value between 0 and 255
gamepad.right_trigger(value=255)  # value between 0 and 255
gamepad.left_joystick(x_value=0, y_value=128)  # value between 0 and 255
gamepad.right_joystick(x_value=0, y_value=255)  # value between 0 and 255

gamepad.update()

Triggers and joysticks (float values):

gamepad.left_trigger_float(value_float=0.5)  # value between 0.0 and 1.0
gamepad.right_trigger_float(value_float=1.0)  # value between 0.0 and 1.0
gamepad.left_joystick_float(x_value_float=-0.5, y_value_float=0.0)  # values between -1.0 and 1.0
gamepad.right_joystick_float(x_value_float=-1.0, y_value_float=0.8)  # values between -1.0 and 1.0

gamepad.update()
  • Note: The Y axis on joysticks is inverted for consistency with the X360 API.

Directional pad (hat):

gamepad.directional_pad(direction=vg.DS4_DPAD_DIRECTIONS.DS4_BUTTON_DPAD_NORTHWEST)
gamepad.update()

Directions for the directional pad are defined in DS4_DPAD_DIRECTIONS

Reset to default state:

gamepad.reset()

gamepad.update()

Metadata

Release files for pyvjoystick 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyvjoystick 1.2.0
File Size Uploaded Provenance Actions
pyvjoystick-1.2.0.tar.gz 133.4 kB Without provenance Details for pyvjoystick-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyvjoystick 1.2.0
File Interpreter ABI Platform Actions
pyvjoystick-1.2.0-py3-none-any.whl Python 3 none any Details for pyvjoystick-1.2.0-py3-none-any.whl

Total release size: 272.4 kB

Release files / pyvjoystick-1.2.0.tar.gz

Download URL pyvjoystick-1.2.0.tar.gz
Size 133.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7cf65fa598dfc50de04a985a6514435e89cf2227e8199133f48acb725ee14a3c
BLAKE2b-256 checksum
How to use checksums
a526e9f309b8369c0634f3b09fb4a5a00bc639cda56b67dc5d38062fb06f74b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Windows/11

Release files / pyvjoystick-1.2.0-py3-none-any.whl

Download URL pyvjoystick-1.2.0-py3-none-any.whl
Size 139.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2a0ea3d34b09a39ee9290e97f7d5c95f989eb2e98c6c49e5500d3df24b53a61
BLAKE2b-256 checksum
How to use checksums
3d1b25053d7a39343d8d2acd3ab73a134e7d9143a61d70d8e49e8a21c362a3b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Windows/11

Security for pyvjoystick 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page