Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // == Xbox Cloud Gaming Keyboard/Mouse to Controller Mapper v10.2 ==
- // == !! EXTREMELY EXPERIMENTAL - Micro-Movements & MANUAL Inventory-Based Anti-Recoil !! ==
- // == !! Focus: Chromebook Compatibility & Aggressive Key Capture for Aim Assist Maintenance !! ==
- // == !! ADS mapped to 'Q' key !! ==
- // == Adds simulated ADS Sens, MANUAL Anti-Recoil (Press 1-5), EXPERIMENTAL Aim Stick Micro-Movements when ADS ==
- // == WARNING: Micro-movements are highly speculative, may not work, may worsen aim, require tuning (RADIUS/SPEED) ==
- // == WARNING: Anti-Recoil requires MANUAL weapon type selection (keys 1-5) & tuning per type. See ANTI_RECOIL_STRENGTHS config ==
- // == WARNING: Script attempts to capture ALL common keys (letters, numbers, symbols) to potentially maintain controller input mode. ==
- // == tip for best aim assist: exit Fullscreen then click exit Fullscreen, execute the script and press ur fullscreen key on ur keyboard on Chromebook ==
- // == TOGGLE SCRIPT ON/OFF: Press the 'End' key. (May be Fn+RightArrow on Chromebooks. Change TOGGLE_KEY if needed) ==
- // == OPTIMAL AIM ASSIST TIP: Avoid browser fullscreen; use windowed or Chromebook's fullscreen KEY (if available). ==
- (function() {
- let masterEnable = true; // Master toggle for the script
- const TOGGLE_KEY = 'end'; // Key to turn the script on/off. Change if needed (e.g., '[', ']')
- console.log(`Initializing Experimental KBM Mapper v10.2 (Chromebook Focus, Q for ADS)... Toggle Key: ${TOGGLE_KEY.toUpperCase()}`);
- console.warn(">>> EXTREME WARNING: MICRO-MOVEMENTS & ANTI-RECOIL ACTIVE. HIGH BAN RISK. TUNE VALUES. HARD REFRESH FIRST! <<<");
- console.warn(">>> Micro-movements SPECULATIVE. Anti-Recoil requires MANUAL SELECTION (Keys 1-5) & TUNING. <<<");
- console.warn(">>> Capturing most standard keys to try and preserve Aim Assist. <<<");
- console.log(`>>> Press '${TOGGLE_KEY.toUpperCase()}' key to toggle the script ON/OFF <<<`);
- // --- Configuration ---
- const MOUSE_SENSITIVITY_X = 0.025; // Adjust for touchpad feel
- const MOUSE_SENSITIVITY_Y = 0.025; // Adjust for touchpad feel
- const ADS_SENSITIVITY_MULTIPLIER = 1.75;
- const MOUSE_DECAY = 0.0; // Might need less decay with touchpad? Experiment.
- const STATE_POLLING_RATE_MS = 16; // ~60Hz
- const CONNECTION_DISPATCH_RATE_MS = 100;
- const AXIS_DEADZONE = 0.05;
- // --- Anti-Recoil Configuration ---
- const FIRE_BUTTON_INDEX = 7; // RT (Right Trigger - Mapped to Mouse 0 / Touchpad Tap)
- const ENABLE_ANTI_RECOIL = true;
- const ANTI_RECOIL_STRENGTHS = { // TUNE THESE VALUES! Positive = Pull Down.
- 'default': 0.010, // Press '1'
- 'ar': 0.015, // Press '2'
- 'smg': 0.025, // Press '3'
- 'shotgun': 0.005, // Press '4'
- 'other': 0.008 // Press '5' (Pistol/Sniper etc)
- };
- let currentWeaponType = 'default'; // Tracks selected weapon type
- // --- Micro-Movement Configuration ---
- const ADS_BUTTON_INDEX = 6; // LT (Left Trigger - Mapped to 'Q' key)
- const ENABLE_MICRO_MOVEMENTS = false;
- const MICRO_MOVEMENT_RADIUS = 0.02; // <<< TUNE THIS! (0.01 - 0.05)
- const MICRO_MOVEMENT_SPEED = 0.1; // <<< TUNE THIS! (0.05 - 0.3)
- // --- Key Mapping --- (Focus on common Fortnite keys, 'Q' for ADS)
- const keyMap = {
- // Movement
- 'w': { t: 'a', a: 1, v: -1 }, // Left Stick Up
- 's': { t: 'a', a: 1, v: 1 }, // Left Stick Down
- 'a': { t: 'a', a: 0, v: -1 }, // Left Stick Left
- 'd': { t: 'a', a: 0, v: 1 }, // Left Stick Right
- // Actions
- ' ': { t: 'b', i: 0 }, // Jump (A)
- 'shift': { t: 'b', i: 10 }, // Sprint (LS Click) - Use Left Shift
- 'control': { t: 'b', i: 11 }, // Crouch (RS Click) - Use Left Control
- 'r': { t: 'b', i: 2 }, // Reload (X)
- 'e': { t: 'b', i: 3 }, // Use/Interact (Y)
- 'f': { t: 'b', i: 5 }, // Pickaxe (RB)
- 'g': { t: 'b', i: 1 }, // Edit? / Alt Interact? (B) - Adjust as needed
- 'c': { t: 'b', i: 4 }, // Switch Mode? / Cycle? (LB) - Adjust as needed (WAS 'c')
- // Inventory / Map / Menu
- 'escape': { t: 'b', i: 9 }, // Menu/Pause (Start)
- 'tab': { t: 'b', i: 8 }, // Inventory (View/Select)
- 'm': { t: 'b', i: 8 }, // Map (also View/Select - Fortnite often uses same)
- // Aim / Fire
- 'q': { t: 'b', i: ADS_BUTTON_INDEX }, // *** ADS (LT) mapped to Q ***
- // Building (Mapped to D-Pad - Adjust if needed)
- 'z': { t: 'b', i: 14 }, // D-pad Down (e.g., Floor)
- 'x': { t: 'b', i: 15 }, // D-pad Right (e.g., Stair)
- // 'c': { t: 'b', i: 13 }, // D-pad Left (e.g., Wall) - CONFLICTS with 'c' above, choose one or remap
- 'v': { t: 'b', i: 12 }, // D-pad Up (e.g., Roof)
- // Keys '1' to '5' are reserved for anti-recoil selection below
- };
- const mouseMap = {
- 0: { t: 'b', i: FIRE_BUTTON_INDEX }, // Left Mouse / Touchpad Tap -> Fire (RT)
- // Mouse Button 2 (Right Click) is NOT mapped to ADS anymore
- // 1: Middle mouse? Map to something if needed (e.g., ping - D-Pad Up: i: 12)
- // 1: { t: 'b', i: 12 }, // Example: Middle Mouse -> Ping (D-Pad Up)
- };
- // --- State Tracking ---
- const controllerState = {
- axes: [0.0, 0.0, 0.0, 0.0],
- buttons: Array(17).fill(false).map((_, i) => ({ pressed: false, touched: false, value: 0.0, index: i })),
- axisKeyPresses: { 0: { neg: false, pos: false }, 1: { neg: false, pos: false } }, // For WASD axes
- mouseDeltaX: 0, mouseDeltaY: 0, isConnected: true, timestamp: performance.now(),
- microMovementAngle: 0
- };
- let pointerLocked = false;
- let stateIntervalId = null;
- let connectionIntervalId = null;
- let gameAreaElement = null;
- const originalGetGamepads = navigator.getGamepads; // Store original function
- // --- Gamepad Object Construction --- (No changes needed)
- function createGamepadObject() {
- const axes = controllerState.axes.map(val => Math.abs(val) < AXIS_DEADZONE ? 0.0 : val);
- const buttons = controllerState.buttons.slice(0, 17).map(b => ({
- pressed: b.pressed, touched: b.touched, value: b.value,
- }));
- return {
- axes: axes, buttons: buttons, connected: controllerState.isConnected,
- id: "KBM Emulated Xbox Controller v10.2 (AR+MM, Q-ADS)", index: 0, mapping: "standard", timestamp: controllerState.timestamp,
- };
- }
- // --- Core Simulation Function --- (No changes needed)
- function updateAndSimulateGamepad() {
- if (!masterEnable) return;
- let currentSensX = MOUSE_SENSITIVITY_X;
- let currentSensY = MOUSE_SENSITIVITY_Y;
- const isADS = controllerState.buttons[ADS_BUTTON_INDEX].pressed; // Reads state from 'Q' key now
- const isFiring = controllerState.buttons[FIRE_BUTTON_INDEX].pressed; // Reads state from Mouse 0 / Tap
- if (isADS) {
- currentSensX *= ADS_SENSITIVITY_MULTIPLIER;
- currentSensY *= ADS_SENSITIVITY_MULTIPLIER;
- }
- let targetRX = controllerState.axes[2];
- let targetRY = controllerState.axes[3];
- if (pointerLocked) {
- targetRX *= MOUSE_DECAY;
- targetRY *= MOUSE_DECAY;
- targetRX += controllerState.mouseDeltaX * currentSensX;
- targetRY += controllerState.mouseDeltaY * currentSensY;
- if (ENABLE_MICRO_MOVEMENTS && isADS) {
- const angle = controllerState.microMovementAngle;
- const microX = Math.cos(angle) * MICRO_MOVEMENT_RADIUS;
- const microY = Math.sin(angle) * MICRO_MOVEMENT_RADIUS;
- targetRX += microX; targetRY += microY;
- controllerState.microMovementAngle = (angle + MICRO_MOVEMENT_SPEED) % (2 * Math.PI);
- }
- if (ENABLE_ANTI_RECOIL && isFiring) {
- const recoilStrength = ANTI_RECOIL_STRENGTHS[currentWeaponType] || ANTI_RECOIL_STRENGTHS['default'];
- targetRY += recoilStrength;
- }
- controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0;
- } else {
- targetRX = 0; targetRY = 0;
- controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0;
- controllerState.microMovementAngle = 0;
- }
- controllerState.axes[0] = Math.max(-1, Math.min(1, controllerState.axes[0]));
- controllerState.axes[1] = Math.max(-1, Math.min(1, controllerState.axes[1]));
- controllerState.axes[2] = Math.max(-1, Math.min(1, targetRX));
- controllerState.axes[3] = Math.max(-1, Math.min(1, targetRY));
- controllerState.timestamp = performance.now();
- }
- // --- Event Handlers --- (No changes needed in logic, just uses the updated keyMap/mouseMap)
- function shouldCaptureKey(key, code) {
- if (key === TOGGLE_KEY) return false;
- if (key.length === 1 && ((key >= 'a' && key <= 'z') || (key >= '0' && key <= '9'))) return true;
- const commonSymbols = ['`', '-', '=', '[', ']', '\\', ';', '\'', ',', '.', '/', '~', '_', '+', '{', '}', '|', ':', '"', '<', '>', '?'];
- if (commonSymbols.includes(key)) return true;
- const relevantCodes = ['Tab', 'CapsLock', 'Backspace', 'Enter', 'Escape', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'];
- if (relevantCodes.includes(code)) return true;
- return false;
- }
- function handleKeyDown(event) {
- const keyLower = event.key.toLowerCase();
- if (keyLower === TOGGLE_KEY) { toggleScript(); event.preventDefault(); event.stopPropagation(); return; }
- if (!masterEnable) return;
- const mappedKey = (event.code === 'ControlLeft' || event.code === 'ControlRight') ? 'control' :
- (event.code === 'ShiftLeft' || event.code === 'ShiftRight') ? 'shift' : keyLower;
- if (ENABLE_ANTI_RECOIL && ['1', '2', '3', '4', '5'].includes(mappedKey)) {
- const weaponTypes = ['default', 'ar', 'smg', 'shotgun', 'other'];
- const index = parseInt(mappedKey) - 1;
- if (index >= 0 && index < weaponTypes.length) {
- currentWeaponType = weaponTypes[index];
- console.log(`Anti-Recoil mode set to: ${currentWeaponType.toUpperCase()} (Strength: ${ANTI_RECOIL_STRENGTHS[currentWeaponType]})`);
- event.preventDefault(); event.stopPropagation(); return;
- }
- }
- const mapping = keyMap[mappedKey];
- if (mapping) {
- event.preventDefault(); event.stopPropagation();
- if (mapping.t === 'b') {
- const button = controllerState.buttons[mapping.i];
- if (!button.pressed) { button.pressed = true; button.touched = true; button.value = 1.0; }
- } else if (mapping.t === 'a') {
- const axisState = controllerState.axisKeyPresses[mapping.a];
- if (mapping.v < 0) axisState.neg = true; else axisState.pos = true;
- if (axisState.neg && axisState.pos) controllerState.axes[mapping.a] = 0;
- else controllerState.axes[mapping.a] = axisState.neg ? -1.0 : 1.0;
- }
- } else if (shouldCaptureKey(mappedKey, event.code)) {
- event.preventDefault(); event.stopPropagation();
- }
- }
- function handleKeyUp(event) {
- const keyLower = event.key.toLowerCase();
- if (keyLower === TOGGLE_KEY) { event.preventDefault(); event.stopPropagation(); return; }
- if (!masterEnable) return;
- const mappedKey = (event.code === 'ControlLeft' || event.code === 'ControlRight') ? 'control' :
- (event.code === 'ShiftLeft' || event.code === 'ShiftRight') ? 'shift' : keyLower;
- if (ENABLE_ANTI_RECOIL && ['1', '2', '3', '4', '5'].includes(mappedKey)) {
- event.preventDefault(); event.stopPropagation(); return;
- }
- const mapping = keyMap[mappedKey];
- if (mapping) {
- event.preventDefault(); event.stopPropagation();
- if (mapping.t === 'b') {
- const button = controllerState.buttons[mapping.i];
- if (button.pressed) { button.pressed = false; button.touched = false; button.value = 0.0; }
- } else if (mapping.t === 'a') {
- const axisState = controllerState.axisKeyPresses[mapping.a];
- if (mapping.v < 0) axisState.neg = false; else axisState.pos = false;
- if (axisState.neg) controllerState.axes[mapping.a] = -1.0;
- else if (axisState.pos) controllerState.axes[mapping.a] = 1.0;
- else controllerState.axes[mapping.a] = 0.0;
- }
- } else if (shouldCaptureKey(mappedKey, event.code)) {
- event.preventDefault(); event.stopPropagation();
- }
- }
- function handleMouseDown(event) { // Handles touchpad tap for firing
- if (!masterEnable) return;
- const mapping = mouseMap[event.button]; // Should only match button 0 now
- if (!mapping || (!pointerLocked && event.target !== gameAreaElement)) return;
- event.preventDefault(); event.stopPropagation();
- if (mapping.t === 'b') { // Fire button
- const button = controllerState.buttons[mapping.i];
- if (!button.pressed) { button.pressed = true; button.touched = true; button.value = 1.0; }
- }
- }
- function handleMouseUp(event) { // Handles touchpad tap release
- if (!masterEnable) return;
- const mapping = mouseMap[event.button]; // Should only match button 0
- if (!mapping) return;
- event.preventDefault(); event.stopPropagation();
- if (mapping.t === 'b') { // Fire button release
- const button = controllerState.buttons[mapping.i];
- if (button.pressed) { button.pressed = false; button.touched = false; button.value = 0.0; }
- }
- }
- function handleMouseMove(event) { // Handles touchpad movement for aiming
- if (!masterEnable || !pointerLocked) return;
- event.preventDefault(); event.stopPropagation();
- const movementX = event.movementX || 0; const movementY = event.movementY || 0;
- controllerState.mouseDeltaX += movementX; controllerState.mouseDeltaY += movementY;
- }
- function handlePointerLockChange() {
- const lockedElement = document.pointerLockElement;
- if (masterEnable && lockedElement === gameAreaElement) {
- console.log('%cPointer Locked', 'color: lightgreen; font-weight: bold;'); pointerLocked = true;
- } else {
- if (pointerLocked) { console.warn(`Pointer Unlocked.`); }
- pointerLocked = false;
- controllerState.axes[2] = 0; controllerState.axes[3] = 0;
- controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0;
- controllerState.microMovementAngle = 0;
- Object.values(mouseMap).forEach(mapping => { // Release Fire button if lock lost
- if (mapping.t === 'b') {
- const button = controllerState.buttons[mapping.i];
- button.pressed = false; button.touched = false; button.value = 0.0;
- }
- });
- // Also release ADS ('q') button if lock is lost
- const adsButton = controllerState.buttons[ADS_BUTTON_INDEX];
- if (adsButton.pressed) { adsButton.pressed = false; adsButton.touched = false; adsButton.value = 0.0; }
- }
- }
- function requestPointerLock() {
- if (!masterEnable) return;
- if (!gameAreaElement) { console.error("Cannot request pointer lock: Game area element not found."); return; }
- if (document.pointerLockElement !== gameAreaElement) {
- console.log("Requesting pointer lock on:", gameAreaElement);
- gameAreaElement.requestPointerLock().catch(e => { console.error("Pointer lock request failed:", e); });
- }
- }
- function dispatchConnectionEvent() {
- if (!masterEnable) return;
- try {
- const gamepad = navigator.getGamepads()[0];
- if (gamepad) {
- const gamepadConnectedEvent = new CustomEvent('gamepadconnected', { detail: { gamepad: gamepad } });
- gamepadConnectedEvent.gamepad = gamepad;
- window.dispatchEvent(gamepadConnectedEvent);
- }
- } catch (e) { console.error("Error dispatching periodic connection event:", e); }
- }
- // --- Master Toggle Function --- (No changes needed)
- function toggleScript() {
- masterEnable = !masterEnable;
- if (masterEnable) {
- console.log("%cKBM Script ENABLED", "color: lightgreen; font-weight: bold;");
- navigator.getGamepads = function() { return [createGamepadObject(), null, null, null]; };
- console.log("Gamepad override RE-ENABLED.");
- if (gameAreaElement && !document.pointerLockElement) { requestPointerLock(); }
- console.log("Resuming simulation and connection dispatch.");
- } else {
- console.warn("%cKBM Script DISABLED", "color: orange; font-weight: bold;");
- controllerState.axes.fill(0.0);
- controllerState.buttons.forEach(b => { b.pressed = false; b.touched = false; b.value = 0.0; });
- controllerState.axisKeyPresses = { 0: { neg: false, pos: false }, 1: { neg: false, pos: false } };
- controllerState.mouseDeltaX = 0; controllerState.mouseDeltaY = 0;
- controllerState.microMovementAngle = 0;
- currentWeaponType = 'default';
- if (document.pointerLockElement) { document.exitPointerLock(); } else { pointerLocked = false; }
- navigator.getGamepads = function() { return [null, null, null, null]; };
- console.log("Gamepad override reports NO CONTROLLER.");
- try {
- const gamepadDisconnectedEvent = new CustomEvent('gamepaddisconnected', { detail: { gamepad: { index: 0 } } });
- window.dispatchEvent(gamepadDisconnectedEvent);
- console.log("Dispatched gamepad DISCONNECT event.");
- } catch(e) { console.error("Error dispatching disconnect event:", e); }
- console.log(`Input released. Press '${TOGGLE_KEY.toUpperCase()}' again to re-enable.`);
- }
- }
- // --- Initialization --- (No changes needed)
- function initialize() {
- console.log("Attempting to find game area element...");
- gameAreaElement = document.getElementById('game-stream') || document.querySelector('video[playsinline]') || document.querySelector('video') || document.body;
- if (!gameAreaElement || gameAreaElement === document.body) {
- console.warn("Could not find specific game stream element, using document.body."); gameAreaElement = document.body;
- } else { console.log("Found game area element:", gameAreaElement); }
- navigator.getGamepads = function() {
- if (!masterEnable) return [null, null, null, null];
- return [createGamepadObject(), null, null, null];
- };
- console.log("Initial navigator.getGamepads override set.");
- window.addEventListener('keydown', handleKeyDown, { capture: true });
- window.addEventListener('keyup', handleKeyUp, { capture: true });
- const mouseEventTarget = gameAreaElement;
- mouseEventTarget.addEventListener('mousemove', handleMouseMove, { capture: true });
- mouseEventTarget.addEventListener('mousedown', handleMouseDown, { capture: true });
- mouseEventTarget.addEventListener('mouseup', handleMouseUp, { capture: true });
- document.addEventListener('pointerlockchange', handlePointerLockChange, false);
- if (gameAreaElement) {
- gameAreaElement.addEventListener('click', requestPointerLock);
- console.log(">>> CLICK THE GAME AREA TO ENABLE MOUSE AIM (Touchpad Aim) <<<");
- } else { console.error("No suitable game area element found for pointer lock!"); }
- if(masterEnable) {
- try { dispatchConnectionEvent(); console.log("Dispatched initial gamepadconnected event."); }
- catch (e) { console.error("Error dispatching initial connection event:", e); }
- }
- stateIntervalId = setInterval(updateAndSimulateGamepad, STATE_POLLING_RATE_MS);
- connectionIntervalId = setInterval(dispatchConnectionEvent, CONNECTION_DISPATCH_RATE_MS);
- console.log(`%cKBM Mapper V10.2 Active! State polling ID: ${stateIntervalId}, Connection dispatch ID: ${connectionIntervalId}.`, "color: yellow;");
- if (ENABLE_ANTI_RECOIL) console.log(`Manual Anti-Recoil ACTIVE. Press 1-5 for weapon type. Initial: ${currentWeaponType.toUpperCase()}. TUNE STRENGTHS!`); else console.log("Anti-Recoil DISABLED.");
- if (ENABLE_MICRO_MOVEMENTS) console.log(`Micro-Movements ACTIVE when ADS (Q). Radius: ${MICRO_MOVEMENT_RADIUS}, Speed: ${MICRO_MOVEMENT_SPEED}. TUNE THESE!`); else console.log("Micro-Movements DISABLED.");
- console.warn(">>> REMEMBER: HIGH BAN RISK with these features enabled. Use responsibly! <<<");
- console.log(`>>> Script is ON. Press '${TOGGLE_KEY.toUpperCase()}' to turn OFF. <<<`);
- console.log("To fully stop/remove, refresh page or type: stopKbmMapper();");
- }
- // --- Cleanup Function --- (No changes needed)
- window.stopKbmMapper = function() {
- console.log("Stopping KBM Mapper V10.2...");
- masterEnable = false;
- if (stateIntervalId) clearInterval(stateIntervalId); if (connectionIntervalId) clearInterval(connectionIntervalId);
- stateIntervalId = null; connectionIntervalId = null;
- window.removeEventListener('keydown', handleKeyDown, { capture: true }); window.removeEventListener('keyup', handleKeyUp, { capture: true });
- if (gameAreaElement) {
- gameAreaElement.removeEventListener('mousemove', handleMouseMove, { capture: true }); gameAreaElement.removeEventListener('mousedown', handleMouseDown, { capture: true });
- gameAreaElement.removeEventListener('mouseup', handleMouseUp, { capture: true }); gameAreaElement.removeEventListener('click', requestPointerLock);
- }
- document.removeEventListener('pointerlockchange', handlePointerLockChange, false);
- if (document.pointerLockElement) { document.exitPointerLock(); }
- pointerLocked = false;
- navigator.getGamepads = originalGetGamepads; // Restore original
- console.log("KBM Mapper stopped. Event listeners removed. Original Gamepad behavior restored. Refresh recommended.");
- };
- // --- Start the script ---
- initialize();
- })(); // End of IIFE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement