tidzo / pyvjoy Goto Github PK
View Code? Open in Web Editor NEWPython Bindings for vJoy (http://vjoystick.sourceforge.net)
Python Bindings for vJoy (http://vjoystick.sourceforge.net)
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.
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.
Hi,
I have an xbox controller connected to my pc, Now all I would like to do is to simulate the key press as if it were pressed by me in real life :)
Can you help
Thanks
Is it possible to get force feedback through this program? Building racing wheel for dirt rally
Seems like this only works for windows
In _sdk.py vJoyButtonError is referenced, but it's called vJoyButtonException in exceptions.py
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)
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)
Any possibility this could be uploaded to PyPI for easier installation via pip?
The code no longer is working within the _wrapper.py
I've updated
line 7 to
dll_path = os.path.dirname(os.path.abspath(__file__)) + os.sep + dll_filename
and it is working fine.
Also might be a good idea to note this does not work with amd64 dll only the 32bit
What license is this under? I don't see any licensing information. Thanks!
I get an error "name wintypes is not defined" in the _sdk.py file.
sorry wrong program ignore this
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
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!
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 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
vjoydevice.py", line 2, in
from pyvjoy.constants import *
ModuleNotFoundError: No module named 'pyvjoy'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.