Gamepad

"""Example of using gamepad.

We are assuming that we have connected to a session like in 'client.py'
"""

from pyremoteplay import RPDevice
from pyremoteplay.gamepad import Gamepad

ip_address = "192.168.0.2"
device = RPDevice(ip_address)
gamepads = Gamepad.get_all()
gamepad = gamepads[0]  # Use first gamepad

###########
# After connecting to device session.
###########

if not gamepad.available:
    print("Gamepad not available")
gamepad.controller = device.controller

# We can now use the gamepad.

# Load custom mapping.
gamepad.load_map("path-to-mapping.yaml")


# When done using
gamepad.close()

Mappings

For DualShock 4 and DualSense controllers, the appropriate mapping will be set automatically.

Other controllers are supported but will likely need a custom mapping. This can be done by creating a .yaml file and then loading it at runtime.

Gamepad support is provided through pygame.

For more information on mappings see the pygame docs.

DualShock 4 Mapping Example

# DualShock 4 Map.

# DualShock 4 does not have hats

button:
    0: CROSS
    1: CIRCLE
    2: SQUARE
    3: TRIANGLE
    4: SHARE
    5: PS
    6: OPTIONS
    7: L3
    8: R3
    9: L1
    10: R1
    11: UP
    12: DOWN
    13: LEFT
    14: RIGHT
    15: TOUCHPAD
axis:
    0: LEFT_X
    1: LEFT_Y
    2: RIGHT_X
    3: RIGHT_Y
    4: L2
    5: R2
hat:

Xbox 360 Mapping Example

# Xbox 360 Map

# D-Pad buttons are mapped to hat

button:
    0: CROSS
    1: CIRCLE
    2: SQUARE
    3: TRIANGLE
    4: L1
    5: R1
    6: SHARE
    7: OPTIONS
    8: L3
    9: R3
    10: PS
axis:
    0: LEFT_X
    1: LEFT_Y
    2: L2
    3: RIGHT_X
    4: RIGHT_Y
    5: R2
hat:
    left: LEFT
    right: RIGHT
    down: DOWN
    up: UP