Overview
docs |
|
|---|---|
package |
Library for xbox controllers.
Free software: MIT License
Installation
pip install robot-xbox-controller
You can also install the in-development version with:
pip install https://github.com/fmorton/robot-xbox-controller/archive/main.zip
Xbox Controller Example
import pygame
from robot.xbox_controller import XboxController
controller = XboxController().connect()
print("Controller 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"Controller axis {event.axis} value {event.value}")
elif event.type == pygame.JOYBUTTONDOWN:
print(f"Button {event.button} pressed on controller {event.joy}")
if event.button == XboxController.BUTTON_XBOX:
running = False
Xbox Controller Example Using run() and the Controller State
The run() loop maintains the state of the controllers and all buttons for processing by your supplied method, “robot” in the example below.
from robot.xbox_controller import XboxController
from time import sleep
def robot(controller):
print("runner", controller.state.state_string())
if controller.state.button_down_milliseconds(XboxController.BUTTON_XBOX):
return False
sleep(XboxController.EVENT_LOOP_DELAY)
return True
controller = XboxController().connect()
controller.run(robot)
The controller.state has the following methods to retrieve the selections.
controller.state.left_x() # returns x value of left controller (-1 means max forward/1 max backward)
controller.state.left_y() # returns y value of left controller (-1 means max left/1 max right)
controller.state.left_axis() # returns left_x, left_y
controller.state.right_x() # returns x value of right controller (-1 means max forward/1 max backward)
controller.state.right_y() # returns y value of right controller (-1 means max left/1 max right)
controller.state.right_axis() # returns right_x, right_y
controller.state.left_trigger() # returns left trigger value (0 to 1 if fully pressed)
controller.state.right_trigger() # returns right trigger value (0 to 1 if fully pressed)
controller.state.left_trigger_raw() # returns left trigger unadjusted value (-1 to 1 if fully pressed)
controller.state.right_trigger_raw() # returns right trigger unadjusted value (-1 to 1 if fully pressed)
controller.state.button_down_seconds(button) # how many seconds "button" has been pressed
controller.state.button_down_milliseconds(button) # how many milliseconds "button" has been pressed
The following button constant values are available in XboxController:
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_MENU = 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
Metadata
Release files for robot-xbox-controller 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| robot_xbox_controller-0.2.0.tar.gz | 6.2 kB | Without provenance | Details for robot_xbox_controller-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| robot_xbox_controller-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for robot_xbox_controller-0.2.0-py3-none-any.whl |
Total release size: 12.2 kB
Release files / robot_xbox_controller-0.2.0.tar.gz
| Download URL | robot_xbox_controller-0.2.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19061a552b10551790833e538ab1b851f12a4be89c913b45991bb51905800183
|
|
BLAKE2b-256 checksum How to use checksums |
833e934b2b5c9eb5fd4328992c04839f109a4c354c08da3b0f86908665bbd9ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / robot_xbox_controller-0.2.0-py3-none-any.whl
| Download URL | robot_xbox_controller-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
031faebfc95e072e184f60e9cd445e3b34998d2b359bfe87049dbeb56c0e5b27
|
|
BLAKE2b-256 checksum How to use checksums |
aecb41cbfe1486a5a5191848476c2c26058ec6f0e59ad511bbb8255f471e9a74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for robot-xbox-controller 0.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.