← Back to Docs
  • index.html
  • Clayground
  • Clayground GameController Module
  • Clayground 2026.14
  • Clayground GameController Module

    The GameController module provides one controller abstraction in two layouts: nes, a stick and two action buttons, and full, two sticks, A/B/X/Y, shoulders, triggers and start/select. It supports multiple input sources that can be switched at runtime; each sets the inputs of the chosen layout.

    Usage

    Import the module:

    import Clayground.GameController

    Keyboard Input

    GameController {
        id: controller
    
        Component.onCompleted: {
            selectKeyboard(Qt.Key_W, Qt.Key_S, Qt.Key_A, Qt.Key_D,
                          Qt.Key_Space, Qt.Key_Return)
        }
    }
    
    Rectangle {
        x: x + controller.axisX * 5
        y: y - controller.axisY * 5
        color: controller.buttonAPressed ? "red" : "blue"
    }

    Touchscreen Gamepad

    GameController {
        id: controller
        Component.onCompleted: selectTouchscreenGamepad()
    }

    Full Layout

    GameController {
        id: controller
        layout: "full"
        Component.onCompleted: selectKeyboard({
            axisX: [Qt.Key_A, Qt.Key_D], axisY: [Qt.Key_S, Qt.Key_W],
            axisRightX: [Qt.Key_J, Qt.Key_L], axisRightY: [Qt.Key_K, Qt.Key_I],
            buttonA: Qt.Key_Space, buttonB: Qt.Key_Shift,
            buttonX: Qt.Key_F, buttonY: Qt.Key_R,
            buttonL1: Qt.Key_Q, buttonR1: Qt.Key_E,
            triggerL2: Qt.Key_1, triggerR2: Qt.Key_3,
            buttonSelect: Qt.Key_Tab, buttonStart: Qt.Key_Return
        })
    }

    Physical Gamepad

    GameController {
        id: controller
        layout: "full"
        function pickSource() {
            if (numConnectedGamepads > 0) selectGamepad(0)
            else selectTouchscreenGamepad()
        }
        Component.onCompleted: pickSource()
        onNumConnectedGamepadsChanged: pickSource()
    }

    Input Sources

    See also GameController.

    GameController

    A unified game input system supporting keyboard, gamepad, and touchscreen

    GamepadHub

    Internal singleton listing the connected physical gamepads