Greasy Fork镜像 还支持 简体中文。

PCOL-ASSIST

为http://www.heyzxz.me/pcol/添加虚拟按键(新增M1键模拟鼠标左键)

目前為 2025-06-24 提交的版本,檢視 最新版本

// ==UserScript==
// @name         PCOL-ASSIST
// @author       葉月Hikaru
// @match        http://www.heyzxz.me/pcol/*
// @version 2.1
// @namespace https://gf.qytechs.cn/users/your-id
// @description 为http://www.heyzxz.me/pcol/添加虚拟按键(新增M1键模拟鼠标左键)
// ==/UserScript==

(function() {
    'use strict';

    // 按键配置(在action键左侧添加M1键,原action键仍为alt功能)
    const keysConfig = [
        // W键左右侧滚轮键(文本互换)
        { key: '+', text: '-', top: 30, left: 40 },
        { key: 'w', text: 'W', top: 30, left: 50 },
        { key: '-', text: '+', top: 30, left: 60 },
        // 顶部功能键
        { key: 'space', text: 'SPACE', top: 30, left: 70 },
        { key: 'x', text: 'X', top: 30, left: 80 },
        { key: 'c', text: 'C', top: 30, left: 90 },
        // C键正下方P键
        { key: 'p', text: 'P', top: 120, left: 90 },
        // 中下部按键
        { key: 'a', text: 'A', top: 120, left: 30 },
        { key: 's', text: 'S', top: 120, left: 50 },
        { key: 'd', text: 'D', top: 120, left: 70 },
        // **新增:action键左侧的M1键(left: 15%,位于原action键左侧)**
        { key: 'M1', text: 'M1', top: 120, left: 15 },
        // 原action键(仍为alt功能,left: 20%,位于M1键右侧)
        { key: 'Alt', text: 'action', top: 120, left: 20 }
    ];

    // 创建按键函数
    function createVirtualKey(keyConfig) {
        const btn = document.createElement('button');
        btn.id = `pcol-assist-${keyConfig.key}-btn`;
        btn.textContent = keyConfig.text;
        btn.style.cssText = `
            position: fixed;
            top: ${keyConfig.top}px;
            left: ${keyConfig.left}%;
            transform: ${keyConfig.left === 50 ? 'translateX(-50%)' : 'translateX(0)'};
            width: 60px;
            height: 60px;
            font-size: ${keyConfig.text === 'SPACE' ? '16px' : '28px'};
            background-color: ${keyConfig.key === 'M1' ? 'rgba(0, 191, 255, 0.9)' : 'rgba(255, 165, 0, 0.9)'};
            color: white;
            border: 2px solid white;
            border-radius: 50%;
            cursor: pointer;
            z-index: 9999;
        `;

        // 模拟按键/鼠标事件
        function triggerEvent(type) {
            if (keyConfig.key === 'M1') {
                // **M1键:模拟鼠标左键点击**
                const mouseEvent = new MouseEvent(type === 'keydown' ? 'mousedown' : 'mouseup', {
                    button: 0,                 // 0为左键
                    bubbles: true,
                    cancelable: true
                });
                const gameCanvas = document.querySelector('canvas');
                gameCanvas?.dispatchEvent(mouseEvent) || document.dispatchEvent(mouseEvent);
            } else if (keyConfig.key === '+' || keyConfig.key === '-') {
                // 滚轮事件(文本互换功能不变)
                const wheelEvent = new WheelEvent('wheel', {
                    deltaY: keyConfig.key === '+' ? -300 : 300,
                    bubbles: true,
                    cancelable: true
                });
                const gameCanvas = document.querySelector('canvas');
                gameCanvas?.dispatchEvent(wheelEvent) || document.dispatchEvent(wheelEvent);
            } else if (keyConfig.key === 'Alt') {
                // action键:触发alt键
                const altEvent = new KeyboardEvent(type, {
                    key: 'Alt', code: 'AltLeft', keyCode: 18,
                    bubbles: true, cancelable: true
                });
                document.dispatchEvent(altEvent);
            } else {
                // 其他按键正常触发
                const key = keyConfig.key === 'space' ? ' ' : keyConfig.key;
                const event = new KeyboardEvent(type, {
                    key: key === ' ' ? 'Spacebar' : key,
                    code: key === ' ' ? 'Space' : `Key${key.toUpperCase()}`,
                    keyCode: key === 'w' ? 87 : key === 'a' ? 65 : key === 's' ? 83 : 
                           key === 'd' ? 68 : key === 'x' ? 88 : key === 'c' ? 67 : key === 'p' ? 80 : 32,
                    bubbles: true,
                    cancelable: true
                });
                const gameCanvas = document.querySelector('canvas');
                gameCanvas?.dispatchEvent(event) || document.dispatchEvent(event);
            }
        }

        // 绑定触摸和鼠标事件
        ['touchstart', 'mousedown'].forEach(e => btn.addEventListener(e, e => {
            e.preventDefault();
            triggerEvent('keydown');
        }));
        ['touchend', 'mouseup'].forEach(e => btn.addEventListener(e, e => {
            e.preventDefault();
            triggerEvent('keyup');
        }));

        document.body.appendChild(btn);
    }

    // 延迟初始化
    setTimeout(() => {
        keysConfig.forEach(createVirtualKey);
        console.log('【PCOL-ASSIST】已添加M1键(位于action键左侧),按下等效于鼠标左键');
    }, 500);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址