Real Key Press Simulation (Toggle with Q and E)

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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
    }
  });
})();