Skip to content

JavaScript and Python examples

These clients connect, authenticate when required, read GET_SETTINGS, print the response, and close. They send no control inputs by default. Follow Get started to enable the server.

ClientDownloadRequirements
JavaScriptclient.mjsNode.js 22.4+; no npm dependencies
Pythonclient.py and requirements.txtPython 3.11+

Enter the key from PlayAbility at a hidden prompt, then run the client in the same terminal. This keeps the key out of your shell history.

macOS (zsh):

Terminal window
read -rs 'PLAYABILITY_WS_KEY?PlayAbility key: '
export PLAYABILITY_WS_KEY

Bash:

Terminal window
read -rs -p 'PlayAbility key: ' PLAYABILITY_WS_KEY
export PLAYABILITY_WS_KEY

Windows PowerShell:

Terminal window
$secureKey = Read-Host 'PlayAbility key' -AsSecureString
$env:PLAYABILITY_WS_KEY = [System.Net.NetworkCredential]::new('', $secureKey).Password
Remove-Variable secureKey

Save the file and run from its folder:

Terminal window
node client.mjs

Save both files in the same folder, then:

Terminal window
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python client.py

On Windows, replace the first two lines with py -3.11 -m venv .venv and .venv\Scripts\Activate.ps1. You can select another installed Python 3.11+ version.

Enable Allow WebSocket Inputs, Main Output, and gamepad output in PlayAbility. Choose a target application where pressing A is appropriate, then run either:

Terminal window
node client.mjs --press-a
Terminal window
python client.py --press-a

The clients check those settings, send a press and an explicit release, and add a 500 ms fallback release. Inputs have no execution acknowledgment: verify the result in PlayAbility or the target application. If the connection drops, check that the button was released.

After testing, close the terminal or clear the key with unset PLAYABILITY_WS_KEY (macOS/Linux) or Remove-Item Env:PLAYABILITY_WS_KEY (PowerShell).