PyObjC GameController Framework

12.1 · active · verified Tue Apr 14

PyObjC is a bridge between Python and Apple's Objective-C frameworks on macOS. The `pyobjc-framework-gamecontroller` package provides Python wrappers for the GameController framework, enabling Python applications to interact with game controllers. The library is actively maintained, with releases frequently aligning with new macOS SDKs and Python versions. Current version is 12.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to list currently connected game controllers using the `GameController` framework. It iterates through available controllers and prints basic information about them.

import objc
from GameController import GCController

def list_game_controllers():
    controllers = GCController.controllers()
    if controllers:
        print(f"Found {len(controllers)} game controllers:")
        for controller in controllers:
            vendor_name = controller.vendorName() or 'Unknown Vendor'
            print(f"  - {vendor_name} {controller.productCategory()} (Type: {controller.controllerType()})")
            if controller.extendedGamepad():
                print("    Extended Gamepad available.")
            elif controller.microGamepad():
                print("    Micro Gamepad available.")
    else:
        print("No game controllers found.")

if __name__ == "__main__":
    list_game_controllers()
    # In a persistent application, you would typically register for
    # GCControllerDidConnectNotification and GCControllerDidDisconnectNotification
    # to dynamically track controller connections/disconnections.

view raw JSON →