Library for xbox controllers.
Project description
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_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_controller-0.1.0.tar.gz.
File metadata
- Download URL: robot_xbox_controller-0.1.0.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 |
aa1541239c749159a670006081e86616aefe1f18a61747c566cafbc7a37488c7
|
|
| MD5 |
67a077d8b84a89bebc4da67b33dc946a
|
|
| BLAKE2b-256 |
f0423a20e42d7ab1ffeafeab3485bc90719b99a7f6ec07eb4d305b609fc42f88
|
File details
Details for the file robot_xbox_controller-0.1.0-py3-none-any.whl.
File metadata
- Download URL: robot_xbox_controller-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 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 |
1f9f4e2f6dbb3c49b10dc5fe5a1103c9d850a5b53c853b5bbc67939fcecdb4ea
|
|
| MD5 |
bad95f96f5fe0459b90d0ad2ed18021e
|
|
| BLAKE2b-256 |
72a3c61ca0a945c515cbc356d6e349e8225ee82234e539b623306094d40d7f16
|