Controller Module

class controller.Controller

Handles input from the controller and exposes constant input state per frame.

class Button(value)

The buttons on the controller.

class Joystick(value)

The joysticks on the controller.

class Trigger(value)

The triggers on the controller.

abstract get_joystick(joystick)

Returns the position of a certain joystick as an (x, y) tuple.

Parameters

joystick (Joystick) – Which joystick to check.

Return type

Tuple[float, float]

Returns

The x and y coordinate of the joystick, with each axis ranging from -1.0 (left or down) to 1.0 (right or up).

Note

The joystick argument must be an associated value of the Joystick enum, which is defined in the Controller module.

Example:

# x and y will be given values from -1.0 to 1.0 based on the position of
# the left joystick
(x, y) = rc.controller.get_joystick(rc.controller.Joystick.LEFT)
abstract get_trigger(trigger)

Returns the position of a certain trigger as a value from 0.0 to 1.0.

Parameters

trigger (Trigger) – Which trigger to check.

Return type

float

Returns

A value ranging from 0.0 (not pressed) to 1.0 (fully pressed) inclusive.

Note

The trigger argument must be an associated value of the Trigger enum, which is defined in the Controller module.

Example:

# Speed will receive a value from 0.0 to 1.0 based on how much the left
# trigger is pressed
speed = rc.controller.get_trigger(rc.controller.Trigger.LEFT)
abstract is_down(button)

Returns whether a certain button is currently pressed.

Parameters

button (Button) – Which button to check.

Return type

bool

Returns

True if button is currently pressed.

Note

The button argument must be an associated value of the Button enum, which is defined in the Controller module.

Example:

# This update function will print a message for every frame in which
# the A button is held down.  Thus, multiple messages will be printed
# if we press and hold the A button
def update():
    if rc.controller.is_down(rc.controller.Button.A):
        print("The A button is currently pressed.")
abstract was_pressed(button)

Returns whether a certain button was pressed this frame.

Parameters

button (Button) – Which button to check.

Return type

bool

Returns

True if button is currently pressed and was not pressed last frame.

Note

The button argument must be an associated value of the Button enum, which is defined in the Controller module.

Example:

# This update function will print a single message each time the A
# button is pressed on the controller
def update():
    if rc.controller.was_pressed(rc.controller.Button.A):
        print("The A button was pressed")
abstract was_released(button)

Returns whether a certain button was released this frame.

Parameters

button (Button) – Which button to check.

Return type

bool

Returns

True if button is currently released and was pressed last frame.

Note

The button argument must be an associated value of the Button enum, which is defined in the Controller module.

Example:

# This update function will print a single message each time the A
# button is released on the controller
def update():
    if rc.controller.was_pressed(rc.controller.Button.A):
        print("The A button was released")