Coder Social home page Coder Social logo

pyvjoy's Introduction

pyvjoy is a set of Python bindings for vJoy (vjoystick.sourceforge.net)

With this library you can easily set Axis and Button values on any vJoy device.  
Low-level bindings are provided in pyvjoy._sdk as well as a (hopefully) slightly more 'Pythonic' API in the pyvjoy.VJoyDevice() object.

Currently vJoyInterface.dll is looked for inside the pyvjoy directory only so place the desired version of that file there to use. (Note: this library currently only works with the x86 dll!)

"Pointy's Joystick Test App" is very useful when testing vJoy and this library: http://www.planetpointy.co.uk/joystick-test-application/

USAGE
-----

import pyvjoy

#Pythonic API, item-at-a-time

j = pyvjoy.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(pyvjoy.HID_USAGE_X, 0x1)

#Set X axis to fully right
j.set_axis(pyvjoy.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

j.data
>>> <pyvjoy._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.



pyvjoy's People

Contributors

dkhachatrian avatar flykido avatar matttron2000 avatar rameshvarun avatar tidzo avatar xylynx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyvjoy's Issues

NameError: name 'vJoyButtonError' is not defined

When I try to set a button that is out of the range of my vjoy controller, I get this error:

  ...
  File "C:\anaconda\lib\site-packages\pyvjoy\vjoydevice.py", line 34, in set_button
    return self._sdk.SetBtn(state,self.rID,buttonID)
  File "C:\anaconda\lib\site-packages\pyvjoy\_sdk.py", line 128, in SetBtn
    raise vJoyButtonError()
NameError: name 'vJoyButtonError' is not defined

In stead of getting a vJoyButtonError-error, I get a NameError stating that vJoyButtonError is not defined.
When taking a look at the code that is raising this exception, I saw that it was importing all exceptions from 'exceptions.py' which did not contain vJoyButtonError, only these.
For my code I just added this in the exceptions.py, which resolved the problem but I thought someone could add this in the package for all.

FFB?

Is it possible to get force feedback through this program? Building racing wheel for dirt rally

vjoy on raspberry pi 4

im trying to use this on a rasperry pi 4 b, and its spitting out Unable to load vJoy SDK DLL. Ensure that vJoyInterface.dll is present /home/pi/.local/lib/python3.9/site-packages/pyvjoy/utils/x64/vJoyInterface.dll: invalid ELF header

i know this is built for windows but is there a way to do it on pi

btw im taking in a number and trying to make that the x cord

import serial.tools.list_ports import pyvjoy j = pyvjoy.VJoyDevice(1) serialInst = serial.Serial() serialInst.baudrate = 9600 serialInst.port = '/dev/ttyACM0' serialInst.open() while True: packet = serialInst.readline() packet = packet.decode('utf').rstrip('\n') if(packet.find("x")==True): packet = packet[:-1] j.set_axis(pyvjoy.HID_USAGE_X, 0x1) else: packet = packet[:-1] j.set_axis(pyvjoy.HID_USAGE_Y, 0x1) import serial.tools.list_ports import pyvjoy j = pyvjoy.VJoyDevice(1) serialInst = serial.Serial() serialInst.baudrate = 9600 serialInst.port = '/dev/ttyACM0' serialInst.open() while True: packet = serialInst.readline() packet = packet.decode('utf').rstrip('\n') if(packet.find("x")==True): packet = packet[:-1] j.set_axis(pyvjoy.HID_USAGE_X, 0x1) else: packet = packet[:-1] j.set_axis(pyvjoy.HID_USAGE_Y, 0x1)

Z Axis flickering when writing data to it

When I'm writing data to the Z axis (I presume it will be the same also on X and Y), the axis is flickering to zero, is there any way I can make a default value (when it is getting no data) or something?

This is my code:

##!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port

import pyautogui
import pyvjoy as vj


class Clutch:
    def __init__(self, sensetivity):
        #self.ev3 = EV3Brick()
        #self.clutchMotor = Motor(Port.C)
        self.sensetivity = sensetivity
        self.writeVjoy()

    def writeVjoy(self):
        j = vj.VJoyDevice(1)

        while True:
            try:
                #x = self.clutchMotor.angle
                x = pyautogui.position()[0] * self.sensetivity
                j.set_axis(vj.HID_USAGE_Z, eval(f"0x{x}"))
                print(f"0x{x}")
                j.update()
                #time.sleep(0.01)
            except Exception as e:
                print(e)


#ev3.speaker.beep(frequency=1000, duration=500)

if __name__ == "__main__":
    clutch = Clutch(10)

PIP compatibility

Any possibility this could be uploaded to PyPI for easier installation via pip?

License?

What license is this under? I don't see any licensing information. Thanks!

fails to import

I get an error "name wintypes is not defined" in the _sdk.py file.

Why an app does not see a button press?

Just a simple button 1 press in loop with 1 sec delay.
I don't see any buttons press neither in an app nor in "vJoy Device properties" window.
Why? Did I miss something?

import pyvjoy

import time

time.sleep(3)

j = pyvjoy.VJoyDevice(1)
while True:
    time.sleep(1)
    j.set_button(1, 1)
    j.update()
    print('button 1')
    time.sleep(1)
    j.set_button(1, 0)
    j.update()
    print('button 1 up')

OS: Windows 11
vJoy: v2.1.9

get button state

Is it possible to get a button state?

eg:
The vJoy Device Buttons can be pushed by a real button with Joystick Gremlin. The program should listen to the buttons and should react (set other buttonstates) according to it. Therefor I would need to get the current button state.

Thanks!

vjoy device not in VJD_STAT_FREE

the line
j = pyvjoy.VJoyDevice(1)

results in the error

Traceback (most recent call last): File "C:\Users\Michael\Documents\Python\pyInputTester.py", line 5, in <module> j = pyvjoy.VJoyDevice(1) File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\pyvjoy\vjoydevice.py", line 25, in __init__ _sdk.AcquireVJD(rID) File "C:\Users\Michael\AppData\Local\Programs\Python\Python36\lib\pyvjoy\_sdk.py", line 53, in AcquireVJD raise vJoyFailedToAcquireException("Cannot acquire vJoy Device because it is not in VJD_STAT_FREE") pyvjoy.exceptions.vJoyFailedToAcquireException: Cannot acquire vJoy Device because it is not in VJD_STAT_FREE

rendering me unable to use the device at all.

Getting error by using vjoy.update()

Getting this error

Traceback (most recent call last):
  File "main.py", line 71, in <module>
    vjoy.update()
  File "C:\Users\Jersh\Desktop\JoyconDrivers\pyvjoy\vjoydevice.py", line 65, in update
    return self._sdk.UpdateVJD(self.rID, self.data)
  File "C:\Users\Jersh\Desktop\JoyconDrivers\pyvjoy\_sdk.py", line 145, in UpdateVJD
    return _vj.UpdateVJD(rID, data)
OSError: exception: access violation writing 0x00000001

No module named 'pyvjoy'

vjoydevice.py", line 2, in
from pyvjoy.constants import *
ModuleNotFoundError: No module named 'pyvjoy'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.