{"id":16654745,"url":"https://github.com/zuzu-typ/xinput-python","last_synced_at":"2025-03-16T23:31:28.814Z","repository":{"id":41526992,"uuid":"192006914","full_name":"Zuzu-Typ/XInput-Python","owner":"Zuzu-Typ","description":"Simple access to the DirectX input API for Python","archived":false,"fork":false,"pushed_at":"2022-03-30T18:04:14.000Z","size":43,"stargazers_count":30,"open_issues_count":5,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T06:23:59.876Z","etag":null,"topics":["controller","controller-api","directx","python","windows","xinput","xinput-controller","xinput-wrapper"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zuzu-Typ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-14T21:20:08.000Z","updated_at":"2025-03-11T17:13:02.000Z","dependencies_parsed_at":"2022-09-12T18:40:54.206Z","dependency_job_id":null,"html_url":"https://github.com/Zuzu-Typ/XInput-Python","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FXInput-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FXInput-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FXInput-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zuzu-Typ%2FXInput-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zuzu-Typ","download_url":"https://codeload.github.com/Zuzu-Typ/XInput-Python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243949951,"owners_count":20373656,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["controller","controller-api","directx","python","windows","xinput","xinput-controller","xinput-wrapper"],"created_at":"2024-10-12T09:50:56.009Z","updated_at":"2025-03-16T23:31:28.446Z","avatar_url":"https://github.com/Zuzu-Typ.png","language":"Python","readme":"# XInput\\-Python  \n## A simple to use interface to the XInput API for Python\\.  \n**XInput\\-Python** provides a few simple methods that can be used to query controller information\\.  \n  \n## Tiny Documentation  \n*XInput is Windows only*  \n### Installation  \nXInput\\-Python is available from the [PyPI](https://pypi.org) using  \n\n    pip install XInput-Python\n  \nIt can be inmported like this:  \n\n    import XInput\n  \n### Using XInput\\-Python  \nXInput\\-Python provides a few functions:  \n`get_connected() -\u003e (bool, bool, bool, bool)` Query which controllers are connected (note: don't query each frame)  \n  \n`get_state(user_index) -\u003e State` Gets the State of the controller `user_index`  \n  \n`get_button_values(state) -\u003e dict` Returns a dictionary, showing which buttons are currently being pressed\\.  \n  \n`get_trigger_values(state) -\u003e (LT, RT)` Returns a tuple with the values of the left and right triggers in range `0.0` to `1.0`  \n  \n`get_thumb_values(state) -\u003e ((LX, LY), (RX, RY))` Returns the values of the thumb sticks, expressed in X and Y ranging from `0.0` to `1.0`  \n  \n`set_vibration(user_index, left_speed, right_speed) -\u003e bool (Success)` Sets the vibration of the left and right motors of `user_index` to values between `0` and `65535` or in range `0.0` to `1.0` respectively\\.  \n  \n`get_battery_information(user_index) -\u003e (\u003ctype\u003e, \u003clevel\u003e)` Returns the battery information for `user_index`  \n  \n`set_deadzone(deadzone, value) -\u003e None` Sets the deadzone values for left/right thumb stick and triggers\\.  \n  \nThe following deadzones exist:  \n`XInput.DEADZONE_LEFT_THUMB` \\- (range 0 to 32767) Left thumb stick deadzone (default is 7849)  \n  \n`XInput.DEADZONE_RIGHT_THUMB` \\- (range 0 to 32767) Right thumb stick deadzone (default is 8689)  \n  \n`XInput.DEADZONE_TRIGGER` \\- (range 0 to 255) Trigger deadzone (default is 30)  \n  \n#### Using Events  \nYou can also use the Event\\-system:  \n\n    events = get_events()\n  \n  \n`get_events` will return a generator that yields instances of the `Event` class\\.  \n  \nThe `Event` class always has the following members:  \n`Event.user_index` (range 0 to 3) \\- the id of the controller that issued this event  \n`Event.type` \\- which type of event was issued  \n  \nThe following events exist:  \n`XInput.EVENT_CONNECTED == 1` \\- a controller with this `user_index` was connected (this event will even occur if the controller was connected before the script was started)  \n  \n`XInput.EVENT_DISCONNECTED == 2` \\- a controller with this `user_index` was disconnected  \n  \n`XInput.EVENT_BUTTON_PRESSED == 3` \\- a button was pressed on the controller `user_index`  \n  \n`XInput.EVENT_BUTTON_RELEASED == 4` \\- a button was released on the controller `user_index`  \n  \n`XInput.EVENT_TRIGGER_MOVED == 5` \\- a trigger was moved on the controller `user_index`  \n  \n`XInput.EVENT_STICK_MOVED == 6` \\- a thumb stick was moved on the controller `user_index`  \n  \n**Button Events**  \nAll button related Events have the following additional members:  \n`Event.button_id` \\- the XInput numerical representation of the button  \n`Event.button` \\- a literal representation of the button  \n  \nThe following buttons exist:  \n\n    \"DPAD_UP\" == 1\n    \"DPAD_DOWN\" == 2\n    \"DPAD_LEFT\" == 4\n    \"DPAD_RIGHT\" == 8\n    \"START\" == 16\n    \"BACK\" == 32\n    \"LEFT_THUMB\" == 64\n    \"RIGHT_THUMB\" == 128\n    \"LEFT_SHOULDER\" == 256\n    \"RIGHT_SHOULDER\" == 512\n    \"A\" == 4096\n    \"B\" == 8192\n    \"X\" == 16384\n    \"Y\" == 32768\n    \n  \n  \n**Trigger Events**  \nAll trigger related Events have the following additional members:  \n`Event.trigger` (either `XInput.LEFT == 0` or `XInput.RIGHT == 1`) \\- which trigger was moved  \n`Event.value` (range 0\\.0 to 1\\.0) \\- by how much the trigger is currently pressed  \n  \n**Stick Events**  \nAll thumb stick related Events have the following additional members:  \n`Event.stick` (either `XInput.LEFT == 0` or `XInput.RIGHT == 1`) \\- which stick was moved  \n`Event.x` (range \\-1\\.0 to 1\\.0) \\- the position of the stick on the X axis  \n`Event.y` (range \\-1\\.0 to 1\\.0) \\- the position of the stick on the Y axis  \n`Event.value` (range 0\\.0 to 1\\.0) \\- the distance of the stick from it's center position  \n`Event.dir` (tuple of X and Y) \\- the direction the stick is currently pointing  \n  \n### Callback events and threading  \nWith the `GamepadThread` class it is possible to handle asynchronous events\\.  \nTo use this feature, extend the `EventHandler` to create one or multiple handlers and add them to the thread\\.  \nThe library will automatically check the status of the gamepad and use the appropriate callback for the triggering event\\.  \nIt is also possible to filter the inputs for every single handler\\.  \nIn case of multiple handlers it is possible to use a list of handlers as argument, as well as the `add_handler()` method and the `remove_handler()` method to remove them\\.  \nFilters can be applied to select events of only certain buttons, trigger or stick\\. Also a \"pressed\\-only\" and \"released\\-only\" filter is available for buttons\\.  \nThe available filters are:  \n\n    \n    BUTTON_DPAD_UP       \n    BUTTON_DPAD_DOWN     \n    BUTTON_DPAD_LEFT     \n    BUTTON_DPAD_RIGHT    \n    BUTTON_START         \n    BUTTON_BACK          \n    BUTTON_LEFT_THUMB    \n    BUTTON_RIGHT_THUMB   \n    BUTTON_LEFT_SHOULDER \n    BUTTON_RIGHT_SHOULDER\n    BUTTON_A             \n    BUTTON_B             \n    BUTTON_X             \n    BUTTON_Y             \n    \n    STICK_LEFT           \n    STICK_RIGHT          \n    TRIGGER_LEFT         \n    TRIGGER_RIGHT        \n    \n    FILTER_PRESSED_ONLY     \n    FILTER_RELEASED_ONLY\n    \n       \n  \nThe filters can be combined by adding them together:  \n  \n\n    filter1 = STICK_LEFT + STICK_RIGHT + BUTTON_DPAD_DOWN + BUTTON_DPAD_UP\n    filter2 = BUTTON_Y + BUTTON_X + FILTER_PRESSED_ONLY\n  \n  \nThe filter can be applied using add\\_filter:  \n  \n\n    handler.add_filter(filter)\n  \n  \n**Example**  \n\n    class MyHandler(EventHandler):\n        def process_button_event(self, event):\n            # put here the code to parse every event related only to the buttons\n        \n        def process_trigger_event(self, event):\n            # event reserved for the two triggers\n        \n        def process_stick_event(self, event):\n            # event reserved for the two sticks\n        \n        def process_connection_event(self, event):\n            # event related to the gamepad status\n        \n    filter = STICK_LEFT + STICK_RIGHT\n    my_handler = MyHandler()\n    my_handler.add_filter(filter)\n    my_gamepad_thread = GamepadThread(my_handler)\n  \n  \nThe thread will start automatically upon creation\\. It is possible to stop and start it again if necessary with the two methods `start()` and `stop()`  \n  \n### Demo  \nRun `XInputTest.py` to see a visual representation of the controller input\\.  \nRun `XInputThreadTest.py` to test the visual representation using the asynchronous callbacks\\.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzuzu-typ%2Fxinput-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzuzu-typ%2Fxinput-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzuzu-typ%2Fxinput-python/lists"}