A python script designed to parse inputs from Xbox controllers and send it to a websocket server. Along with input information, it sends the team number and amount of inputs that the program has sent since it began running.
This script sends the information in a JSON format. An example of what is sent is below:
{
'teamNumber': 123,
'sequenceNumber': 456,
'eventType': "XBOX",
'input':
{
'type': "AXIS",
'key': "R-X",
'value': -0.78910
}
}
teamNumberis the team's assigned team number. This is processed via a command-line argument.sequenceNumberis the number of inputs that has been sent since the program's start.eventTypeis the type of controller usedtypeis either a button input, D-Pad input, or trigger/joystick input. Valid names areAXIS,BUTTON, andDPADkeyis the key, joystick, trigger, or D-Pad input that is being parsed. Input names are- For
type: AXIS:L-Yfor the left joystick's Y-axisL-Xfor the left joystick's X-axisR-Yfor the right joystick's Y-axisR-Xfor the right joystick's X-axisLEFT_TRIGGERfor the left trigger (sometimes called L2)RIGHT_TRIGGERfor the right trigger (sometimes called R2)
- For
type: BUTTON:A_BUTTONB_BUTTONX_BUTTONY_BUTTONLEFT_BUMPERRIGHT_BUMPERVIEW_BUTTONMENU_BUTTONL_JOY_PRESSR_JOY_PRESSXBOX_BUTTONHOME_BUTTON
- For
type: DPAD:DPAD1
- For
valueis as follows:- For
AXIS, the value is a float between-1.0and1.0.- For the X-axis, left is negative and right is positive.
- For the Y-axis, down is negative and up is positive.
- For the triggers, released is negative and depressed is positive.
- For
BUTTON:- Button down is
True. - Button up is
False.
- Button down is
- For
DPAD:- Two nested JSON objects named
xandy. - Left or Down is
-1 - Right or Up is
1 - Neutral position is
0Note: Input is never sent continuously. They are only sent if the value changes.
- Two nested JSON objects named
- For
This script uses the asyncio, pygame, and websockets libraries. They are on PyPI for installation using pip install or can be downloaded from their Gits.
Note: Compilation tested with python 3.7.8
With the required packages installed, use pyinstaller to compile the program for use on machines without python installed.
Install pyinstaller using
pip install pyinstaller
or compile it from the source
The command is
pyinstaller [options] script
Use option -F or --onefile to make the resulting output be one file.
Note that pyinstaller will create multiple files and folders while compiling.
Additionally, pyinstaller cannot compile for any other platform except the platform you are currently using; you can only compile a MacOS app on a machine running MacOS, and you can only compile a Windows app on a machine running Windows.