zuzu-typ / xinput-python Goto Github PK
View Code? Open in Web Editor NEWSimple access to the DirectX input API for Python
License: zlib License
Simple access to the DirectX input API for Python
License: zlib License
Hi,
I connected a LeoBodnar BU0836A with eight axis joystick, windows driver see everything but XInput is not able to catch the joystick .. any idea ?!
i need it for a project
Is there a way to know which type/brand of gamepad is connected? (Logitech, X-box ...) I want to change the button layout in the GUI based on gamepad type
Hi
Thanks for your great work.
when i use your lib for example
elif event.type == EVENT_STICK_MOVED:
if event.stick == RIGHT:
print(event.x , event.y )
it seems the events are discrete not Continuous, i need to reported event.x and event.y very frequently
when i hold STICK_MOVED
any solution ??
Forgive my inexperience working with the library here, but I'm trying to use this library to connect my XBox Controller to my VISCA Camera. When I try to run the attached script in Powershell I get this error message:
import XInput
class Handler(XInput.EventHandler):
ALL_FACE_BUTTONS = XInput.BUTTON_A | XInput.BUTTON_B | XInput.BUTTON_Y | XInput.BUTTON_X
ALL_DPAD_BUTTONS = XInput.BUTTON_DPAD_UP | XInput.BUTTON_DPAD_DOWN | XInput.BUTTON_DPAD_LEFT | XInput.BUTTON_DPAD_RIGHT
ALL_MENU_BUTTONS = XInput.BUTTON_START | XInput.BUTTON_BACK
ALL_THUMB_BUTTONS = XInput.BUTTON_LEFT_THUMB | XInput.BUTTON_RIGHT_THUMB
ALL_SHOULDER_BUTTONS = XInput.BUTTON_LEFT_SHOULDER | XInput.BUTTON_RIGHT_SHOULDER
ALL_BUTTONS = ALL_FACE_BUTTONS | ALL_DPAD_BUTTONS | ALL_MENU_BUTTONS | ALL_THUMB_BUTTONS | ALL_SHOULDER_BUTTONS
# last_stickL_pos = (0.0, 0.0)
# last_stickR_pos = (0.0, 0.0)
def __init__(self, *controllers):
super().__init__(*controllers, filter = Handler.ALL_BUTTONS + XInput.STICK_LEFT + XInput.STICK_RIGHT + XInput.TRIGGER_LEFT + XInput.TRIGGER_RIGHT)
def process_button_event(self, event):
print("(" + str(Event.button) + ") button pressed")
# TODO: Connect button press to set preset command in VISCA
# TODO: Connect shoulder button press to focus in/out in VISCA
def process_trigger_event(self, event):
if(Event.trigger == XInput.LEFT):
print("Trigger L pressed to " + str(Event.value))
if(Event.trigger == XInput.RIGHT):
print("Trigger R pressed to " + str(Event.value))
# TODO: Connect trigger push to camera zoom in/out in VISCA
def process_stick_event(self, event):
if(Event.stick == XInput.LEFT):
print("Stick L moved to " + str(Event.value))
if(Event.stick == XInput.RIGHT):
print("Stick R moved to " + str(Event.value))
# TODO: Check last_stick_pos to see if we need to send a new packet or not
# TODO: Connect stick tilt to camera tilt/pan in VISCA
def process_connection_event(self, event):
print("Controller connected on port " + str(Event.user_index))
my_handler = Handler()
my_handler.add_filter(filter)
my_gamepad_thread = XInput.GamepadThread(my_handler)
Traceback (most recent call last):
File "D:\Church Camera Python Controller\XBoxController.py", line 33, in <module>
my_handler = Handler()
File "D:\Church Camera Python Controller\XBoxController.py", line 13, in __init__
super().__init__(*controllers, filter = Handler.ALL_BUTTONS + XInput.STICK_LEFT + XInput.STICK_RIGHT + XInput.TRIGGER_LEFT + XInput.TRIGGER_RIGHT)
File "C:\Users\thebl\AppData\Local\Programs\Python\Python310\lib\site-packages\XInput.py", line 556, in __init__
self.set_controllers(*controllers)
File "C:\Users\thebl\AppData\Local\Programs\Python\Python310\lib\site-packages\XInput.py", line 582, in set_controllers
raise ValueError("You need to specify at least one controller")
ValueError: You need to specify at least one controller
How do I specify a controller in the script?
When importing package in python 2.7...... I receive an error
Line 555
Def init(self, *controllers, filter = FILTER_NONE):
there is a carrot " ^ " under the " r " in filter syntaxerror: invalid syntax
I was trying out the different functions available and came across this error:
>>> XInput.get_battery_information(XInput.get_state(0))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "XInput.py", line 268, in get_battery_information
XInputGetBatteryInformation(user_index, BATTERY_DEVTYPE_GAMEPAD, battery_information)
File "XInput.py", line 144, in XInputGetBatteryInformation
return libXInput.XInputGetBatteryInformation(dwUserIndex, devType, ctypes.byref(batteryInformation))
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type
Also can I ask what you mean by "You shouldn't check this too frequently" in get_connected
? Is it just due to it being slow?
So it's probably my lack of expertise with async programming speaking here but I could not figure out as to how to detect any button combinations being made on the controller, any way to do so or to implement some the filters to do the same?
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.