Real Key Press Simulation (Toggle with Q and E)

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

  1. // ==UserScript==
  2. // @name Real Key Press Simulation (Toggle with Q and E)
  3. // @namespace http://your-unique-namespace.com
  4. // @version 1.0
  5. // @description Simulates pressing keys 0 and 9 repeatedly. Activate with Q and deactivate with E.
  6. // @author Your Name
  7. // @match *://*/*
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. let intervalId; // Holds the interval ID
  15. let running = false; // Tracks whether the script is running
  16.  
  17. // Function to simulate key press
  18. function simulateKeyPress(key) {
  19. const event = new KeyboardEvent('keydown', {
  20. key: key,
  21. code: `Key${key.toUpperCase()}`,
  22. keyCode: key.charCodeAt(0),
  23. which: key.charCodeAt(0),
  24. bubbles: true,
  25. });
  26. document.dispatchEvent(event);
  27. }
  28.  
  29. // Function to start the key press simulation
  30. function startRepeating() {
  31. if (!running) {
  32. running = true;
  33. console.log('Simulation started');
  34. intervalId = setInterval(() => {
  35. simulateKeyPress('0'); // Simulate pressing "0"
  36. setTimeout(() => {
  37. simulateKeyPress('9'); // Simulate pressing "9"
  38. }, 2890); // Wait 2.89 seconds before pressing "9"
  39. }, 5780); // Repeat every 5.78 seconds
  40. }
  41. }
  42.  
  43. // Function to stop the key press simulation
  44. function stopRepeating() {
  45. if (running) {
  46. clearInterval(intervalId);
  47. running = false;
  48. console.log('Simulation stopped');
  49. }
  50. }
  51.  
  52. // Event listener for key presses
  53. document.addEventListener('keydown', (event) => {
  54. if (event.key === 'q' || event.key === 'Q') {
  55. startRepeating(); // Start simulation on pressing Q
  56. } else if (event.key === 'e' || event.key === 'E') {
  57. stopRepeating(); // Stop simulation on pressing E
  58. }
  59. });
  60. })();