Library for basic xbox joystick controllers.
Project description
docs |
|
|---|---|
package |
Library for basic xbox joystick controllers.
Free software: MIT License
Installation
pip install robot-xbox-joystick
You can also install the in-development version with:
pip install https://github.com/fmorton/robot-xbox-joystick/archive/main.zip
Xbox Joystick Example
import pygame
from robot.xbox_joystick import XboxJoystick
joystick = XboxJoystick().connect()
print("Joystick connected")
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.JOYAXISMOTION:
print(f"Joystick axis {event.axis} value {event.value}")
elif event.type == pygame.JOYBUTTONDOWN:
print(f"Button {event.button} pressed on joystick {event.joy}")
if event.button == XboxJoystick.BUTTON_XBOX:
running = False
Xbox Joystick Example Using run() and the Joystick State
The run() loop maintains the state of the joysticks and all buttons for processing by your supplied method, “robot” in the example below.
from robot.xbox_joystick import XboxJoystick
from time import sleep
def robot(joystick):
print("runner", joystick.state.state_string())
if joystick.state.button_down_milliseconds(XboxJoystick.BUTTON_XBOX):
return False
sleep(XboxJoystick.EVENT_LOOP_DELAY)
return True
joystick = XboxJoystick().connect()
joystick.run(robot)
The joystick.state has the following methods to retrieve the selections from the controller.
joystick.state.left_x() # returns x value of left joystick (-1 means max forward/1 max backward)
joystick.state.left_y() # returns y value of left joystick (-1 means max left/1 max right)
joystick.state.left_axis() # returns left_x, left_y
joystick.state.right_x() # returns x value of right joystick (-1 means max forward/1 max backward)
joystick.state.right_y() # returns y value of right joystick (-1 means max left/1 max right)
joystick.state.right_axis() # returns right_x, right_y
joystick.state.left_trigger() # returns left trigger value (0 to 1 if fully pressed)
joystick.state.right_trigger() # returns right trigger value (0 to 1 if fully pressed)
joystick.state.left_trigger_raw() # returns left trigger unadjusted value (-1 to 1 if fully pressed)
joystick.state.right_trigger_raw() # returns right trigger unadjusted value (-1 to 1 if fully pressed)
joystick.state.button_down_seconds(button) # how many seconds "button" has been pressed
joystick.state.button_down_milliseconds(button) # how many milliseconds "button" has been pressed
The following button constant values are available in XboxJoystick:
BUTTON_A = 0
BUTTON_B = 1
BUTTON_X = 2
BUTTON_Y = 3
BUTTON_VIEW = 4 # left middle button
BUTTON_XBOX = 5 # center middle button
BUTTON_SHARE = 6 # right middle button
BUTTON_LEFT_JOYSTICK = 7
BUTTON_RIGHT_JOYSTICK = 8
BUTTON_LEFT_BUMPER = 9
BUTTON_RIGHT_BUMPER = 10
BUTTON_FORWARD = 11
BUTTON_BACKWARD = 12
BUTTON_LEFT = 13
BUTTON_RIGHT = 14
Testing
To run all the tests run:
pytest -s
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file robot_xbox_joystick-0.0.7.tar.gz.
File metadata
- Download URL: robot_xbox_joystick-0.0.7.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08bd79c89a23369e5ada5b0f4939c6e871daf45a232e855c33f823ab56fa1e30
|
|
| MD5 |
f9ef1b4b3e7b9528163dde8f73a86849
|
|
| BLAKE2b-256 |
0cd6513f5c5785dcfb7bc43da7ccd92a64c720229af702b5fb0570688fb50d84
|
File details
Details for the file robot_xbox_joystick-0.0.7-py3-none-any.whl.
File metadata
- Download URL: robot_xbox_joystick-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
233f06f726d9202a8a2a4ebf2ad230037d5318746de00008740abad3b918ec2f
|
|
| MD5 |
47ff337475129b74e338a9e190e49650
|
|
| BLAKE2b-256 |
4bb4e90638914532a567370f971e2213302ca43c2eafebe7187d402723217d7d
|