@@ -574,7 +574,7 @@ def state(self) -> tuple:
574574 """
575575
576576 def joystick_left (self ) -> tuple [int , int ]:
577- """joystick_left() -> tuple
577+ """joystick_left() -> tuple[int, int]: %
578578
579579 Gets the left joystick position as percentages between -100%
580580 and 100%. The center position is (0, 0). A square deadzone is applied:
@@ -588,7 +588,7 @@ def joystick_left(self) -> tuple[int, int]:
588588 """
589589
590590 def joystick_right (self ) -> tuple [int , int ]:
591- """joystick_right() -> tuple
591+ """joystick_right() -> tuple[int, int]: %
592592
593593 Gets the right joystick position as percentages between -100%
594594 and 100%. The center position is (0, 0). A square deadzone is applied:
@@ -602,7 +602,7 @@ def joystick_right(self) -> tuple[int, int]:
602602 """
603603
604604 def triggers (self ) -> tuple [int , int ]:
605- """triggers() -> tuple
605+ """triggers() -> tuple[int, int]: %
606606
607607 Gets the left and right trigger positions as percentages between 0%
608608 and 100%.
@@ -683,6 +683,110 @@ def rumble(
683683 """
684684
685685
686+ class PlayStationController :
687+ """Use a Sony® PlayStation® controller as a sensor in your projects to
688+ control them remotely.
689+
690+ This has been tested on the DUALSHOCK®4 wireless controller for
691+ PlayStation®4 and the DualSense™ wireless controller for PlayStation®5, but
692+ similar gamepads may also work.
693+
694+ Pair the controller in the hub menu first. When your program
695+ runs, it uses the controller that is currently connected.
696+
697+ For tips on connectivity and pairing, see
698+ :ref:`below <playstation-controller-pairing>`.
699+
700+ .. versionadded:: 4.1
701+ """
702+
703+ buttons = _common .Keypad ([])
704+
705+ def __init__ (self , joystick_deadzone : int = 10 ):
706+ """__init__(joystick_deadzone=10)
707+
708+ Arguments:
709+ joystick_deadzone (Number, %): Joystick deadzone (0 to 100). Values
710+ below this threshold in both axes will be reported as 0 to
711+ prevent stick drift.
712+
713+ Raises:
714+ OSError: If the controller is not connected.
715+ """
716+
717+ def name (self ) -> str | None :
718+ """name() -> str | None
719+
720+ Gets the Bluetooth name of the connected controller.
721+
722+ Returns:
723+ Bluetooth name of the controller, or ``None`` if it is not known.
724+
725+ Raises:
726+ OSError: If the controller is not connected.
727+ """
728+
729+ def joystick_left (self ) -> tuple [int , int ]:
730+ """joystick_left() -> tuple[int, int]: %
731+
732+ Gets the left joystick position as percentages between -100%
733+ and 100%. The center position is (0, 0). A square deadzone is applied:
734+ if both axes are within the deadzone, both are reported as 0.
735+
736+ Returns:
737+ Tuple of X (horizontal) and Y (vertical) position.
738+
739+ Raises:
740+ OSError: If the controller is not connected.
741+ """
742+
743+ def joystick_right (self ) -> tuple [int , int ]:
744+ """joystick_right() -> tuple[int, int]: %
745+
746+ Gets the right joystick position as percentages between -100%
747+ and 100%. The center position is (0, 0). A square deadzone is applied:
748+ if both axes are within the deadzone, both are reported as 0.
749+
750+ Returns:
751+ Tuple of X (horizontal) and Y (vertical) position.
752+
753+ Raises:
754+ OSError: If the controller is not connected.
755+ """
756+
757+ def triggers (self ) -> tuple [int , int ]:
758+ """triggers() -> tuple[int, int]: %
759+
760+ Gets the left (L2) and right (R2) trigger positions as percentages
761+ between 0% and 100%.
762+
763+ Returns:
764+ Tuple of left and right trigger positions.
765+
766+ Raises:
767+ OSError: If the controller is not connected.
768+ """
769+
770+ def dpad (self ) -> int :
771+ """dpad() -> int
772+
773+ Gets the direction-pad value. ``1`` is up, ``2`` is up-right, ``3``
774+ is right, ``4`` is down-right, ``5`` is down, ``6`` is down-left,
775+ ``7`` is left, ``8`` is up-left, and ``0`` is not pressed.
776+
777+ This is essentially the same as reading the state of the
778+ ``Button.UP``, ``Button.RIGHT``, ``Button.DOWN``, and ``Button.LEFT``
779+ buttons, but this method conveniently returns a number that indicates
780+ a direction.
781+
782+ Returns:
783+ Direction-pad position, indicating a direction.
784+
785+ Raises:
786+ OSError: If the controller is not connected.
787+ """
788+
789+
686790# Hide type-only names from jedi completions in the module namespace.
687791if TYPE_CHECKING :
688792 del MaybeAwaitable
0 commit comments