Real Key Press Simulation (Toggle with Q and E)

Simulates pressing keys 0 and 9 repeatedly. Activate with Q and deactivate with E.

当前为 2024-11-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Real Key Press Simulation (Toggle with Q and E)
// @namespace    http://your-unique-namespace.com
// @version      1.0
// @description  Simulates pressing keys 0 and 9 repeatedly. Activate with Q and deactivate with E.
// @author       Your Name
// @match        *://*/*
// @license      MIT
// ==/UserScript==

(function() {
  'use strict';

  let intervalId; // Holds the interval ID
  let running = false; // Tracks whether the script is running

  // Function to simulate key press
  function simulateKeyPress(key) {
    const event = new KeyboardEvent('keydown', {
      key: key,
      code: `Key${key.toUpperCase()}`,
      keyCode: key.charCodeAt(0),
      which: key.charCodeAt(0),
      bubbles: true,
    });
    document.dispatchEvent(event);
  }

  // Function to start the key press simulation
  function startRepeating() {
    if (!running) {
      running = true;
      console.log('Simulation started');
      intervalId = setInterval(() => {
        simulateKeyPress('0'); // Simulate pressing "0"
        setTimeout(() => {
          simulateKeyPress('9'); // Simulate pressing "9"
        }, 2890); // Wait 2.89 seconds before pressing "9"
      }, 5780); // Repeat every 5.78 seconds
    }
  }

  // Function to stop the key press simulation
  function stopRepeating() {
    if (running) {
      clearInterval(intervalId);
      running = false;
      console.log('Simulation stopped');
    }
  }

  // Event listener for key presses
  document.addEventListener('keydown', (event) => {
    if (event.key === 'q' || event.key === 'Q') {
      startRepeating(); // Start simulation on pressing Q
    } else if (event.key === 'e' || event.key === 'E') {
      stopRepeating(); // Stop simulation on pressing E
    }
  });
})();