Speed Stars Controller Config

Map Xbox Triggers (LT/RT) or Bumpers (LB/RB) to Left/Right arrows for Speed Stars

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Speed Stars Controller Config
// @namespace    http://tampermonkey.net
// @version      1.1
// @description  Map Xbox Triggers (LT/RT) or Bumpers (LB/RB) to Left/Right arrows for Speed Stars
// @author       AI Assistant
// @match        *://*://*
// @match        *://*/*
// @match        *://*://*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // BUTTON CONFIGURATION INDEXES (Standard Xbox Layout)
    // LB = 4, RB = 5  |  LT = 6, RT = 7
    const LEFT_INPUT_INDEX = 4; 
    const RIGHT_INPUT_INDEX = 5; 

    // Analog trigger threshold activation sensitivity (0.0 to 1.0)
    const TRIGGER_THRESHOLD = 0.15;

    let leftPressed = false;
    let rightPressed = false;

    // Helper to forge real trusted keyboard events
    function simulateKey(type, keyCode, keyName) {
        const target = document.activeElement || document.body;
        const event = new KeyboardEvent(type, {
            key: keyName,
            code: keyName,
            keyCode: keyCode,
            which: keyCode,
            bubbles: true,
            cancelable: true
        });
        target.dispatchEvent(event);
    }

    // Main Gamepad Polling Loop
    function pollGamepad() {
        const gamepads = navigator.getGamepads ? navigator.getGamepads() : [];
        const gp = gamepads[0]; // Uses the first connected controller

        if (!gp) {
            requestAnimationFrame(pollGamepad);
            return;
        }

        // 1. Read Left Button (LB or LT) status
        const leftButton = gp.buttons[LEFT_INPUT_INDEX];
        const isLeftDown = leftButton ? (leftButton.pressed || leftButton.value > TRIGGER_THRESHOLD) : false;

        if (isLeftDown && !leftPressed) {
            leftPressed = true;
            simulateKey('keydown', 37, 'ArrowLeft');
        } else if (!isLeftDown && leftPressed) {
            leftPressed = false;
            simulateKey('keyup', 37, 'ArrowLeft');
        }

        // 2. Read Right Button (RB or RT) status
        const rightButton = gp.buttons[RIGHT_INPUT_INDEX];
        const isRightDown = rightButton ? (rightButton.pressed || rightButton.value > TRIGGER_THRESHOLD) : false;

        if (isRightDown && !rightPressed) {
            rightPressed = true;
            simulateKey('keydown', 39, 'ArrowRight');
        } else if (!isRightDown && rightPressed) {
            rightPressed = false;
            simulateKey('keyup', 39, 'ArrowRight');
        }

        requestAnimationFrame(pollGamepad);
    }

    // Start looking for the controller loop immediately
    requestAnimationFrame(pollGamepad);
    console.log("Speed Stars Gamepad Mapper Active: Use Bumpers (or edit script variables for Triggers)");
})();