Skip to main content

Simple hooks for PS4 controller

Project description

pyPS4Controller

PyPI version shields.io PyPI pyversions Downloads

pyPS4Controller is a light module designed to provide hooks for PS4 Controller using Python on Linux.

Installation

pip install pyPS4Controller

Usage

from pyPS4Controller.controller import Controller

class MyController(Controller):  # create a custom class for your controller and subclass Controller
    """
    If we want to bind an action to the X button on the controller, we need to override its respective methods.

    Some of the buttons have a binary On/Off state. For example the X, Circle, Square, and Triangle buttons.
    When overriding their respective methods there are no args in the function signature.

    Some controls like the L2, L3, R2 and R3 have a variable On state.
    When overriding their respective method, there is a value argument in the function signature 
    which indicates the degree of the input.
    """    
    def on_x_press(self):
        # Input any code that you want to run when X is pressed
        print("X pressed!")

    def on_x_release(self):
        # Input any code that you want to run when X is released
        print("X released!")

    def on_L3_up(self, value):
        # Input any code that you want to run when left joystick (L3) is pushed up
        # value will indicate the degree of how far the joystick is pushed
        print(f"L3 pushed up: {value}")

    def on_L3_release(self):
        # Input any code that you want to run when left joystick (L3) is back to its resting state
        print("L3 at rest!")

# now make sure the controller is paired over the Bluetooth and turn on the listener
MyController(interface="/dev/input/js0").listen()

Pair PS4 Controller with the Raspberry Pi

See detailed instructions here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyPS4Controller-1.0.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

pyPS4Controller-1.0.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file pyPS4Controller-1.0.3.tar.gz.

File metadata

  • Download URL: pyPS4Controller-1.0.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for pyPS4Controller-1.0.3.tar.gz
Algorithm Hash digest
SHA256 6988bb138959dc8d012ab78e3213d8bb1bb49539b406eba45189c7d708a8292b
MD5 dcf129a0152e4e2c113ca26f0499b388
BLAKE2b-256 646ebecb4843cdb18cf43e0ebdac5647df97c9ab8151862d43c8a888b30c800e

See more details on using hashes here.

File details

Details for the file pyPS4Controller-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyPS4Controller-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.1.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for pyPS4Controller-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cfcc06f03583260dcf7a354e5c3a37db2416c2730fc05a13a24dc829ea6351cb
MD5 9dc271fe0bea618492d98b93ad688b57
BLAKE2b-256 307f6fc3916306b95265b912ba4be8a232fac89ae73fe252360d59784e937e36

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page