您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
为台球游戏添加虚拟按键,新增Alt键开关功能
当前为
// ==UserScript== // @name PCOL-ASSIST // @author 葉月Hikaru // @match http://www.heyzxz.me/pcol/* // @version 2.4 // @namespace https://gf.qytechs.cn/users/your-id // @description 为台球游戏添加虚拟按键,新增Alt键开关功能 // ==/UserScript== (function() { 'use strict'; // 按键配置(移除原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 } ]; // Alt键开关状态(默认关闭) let isAltPressed = false; let altInterval; // 创建按键函数 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: 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 === '+' || 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 { // 其他按键正常触发 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); } // 创建Alt键开关按钮 function createAltToggle() { const toggle = document.createElement('button'); toggle.id = 'pcol-assist-alt-toggle'; toggle.textContent = 'Alt 关'; toggle.style.cssText = ` position: fixed; top: 200px; left: 20%; width: 100px; height: 40px; font-size: 18px; background-color: rgba(0, 128, 255, 0.9); color: white; border: none; border-radius: 5px; cursor: pointer; z-index: 9999; `; // 切换Alt键状态 toggle.addEventListener('click', () => { isAltPressed = !isAltPressed; toggle.textContent = isAltPressed ? 'Alt 开' : 'Alt 关'; if (isAltPressed) { // 持续按下Alt键(通过定时器模拟) altInterval = setInterval(() => { const altEvent = new KeyboardEvent('keydown', { key: 'Alt', code: 'AltLeft', keyCode: 18, bubbles: true, cancelable: true }); document.dispatchEvent(altEvent); }, 100); } else { // 松开Alt键并清除定时器 clearInterval(altInterval); const altEvent = new KeyboardEvent('keyup', { key: 'Alt', code: 'AltLeft', keyCode: 18, bubbles: true, cancelable: true }); document.dispatchEvent(altEvent); } }); document.body.appendChild(toggle); } // 延迟初始化 setTimeout(() => { keysConfig.forEach(createVirtualKey); createAltToggle(); console.log('【PCOL-ASSIST】已添加Alt键开关功能'); }, 500); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址