https://github.com/simplehydrogen/pyxboxcontroller
A simple library for getting the state of a connected XInput device (such as an xbox controller) in Windows.
https://github.com/simplehydrogen/pyxboxcontroller
controller xbox xbox-controller
Last synced: 5 months ago
JSON representation
A simple library for getting the state of a connected XInput device (such as an xbox controller) in Windows.
- Host: GitHub
- URL: https://github.com/simplehydrogen/pyxboxcontroller
- Owner: SimpleHydrogen
- License: mit
- Created: 2022-10-20T13:05:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-24T14:08:23.000Z (about 3 years ago)
- Last Synced: 2025-09-29T09:02:20.438Z (9 months ago)
- Topics: controller, xbox, xbox-controller
- Language: Python
- Homepage:
- Size: 480 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pyxboxcontroller
This module allows for accessing the current state of a connected Xbox controller via the [XInput library](https://learn.microsoft.com/en-gb/windows/win32/xinput/getting-started-with-xinput?redirectedfrom=MSDN#getting-controller-state) on Windows.
## Installation
Simply install using pip
`pip install pyxboxcontroller`
## Importing
`from pyxboxcontroller import XboxController, XboxControllerState`
## Connect to controller
Connect to the controller with id (starting at 0) using:
`controller = XboxController(id)`
## Getting the current state of the controller
The current state of the controller can be gotten with:
`state: XboxControllerState = controller.state`
This returns an `XboxControllerState` object.
Some examples of accessing the states' values:
```python
left_thumbstick_x: float = state.l_thumb_x
right_thumbstick_y: float = state.r_thumb_y
x_pressed: bool = state.x
lb_pressed: bool = state.lb
```
Alternately the state of the button (e.g. x) can be gotten with:
` button_pressed: bool = state.buttons["x"]`
## Examples
To see this code in action, why not try out:
```python
from pyxboxcontroller.examples import example_state_gui
example_state_gui()
```