chess.com, wasd controls

allows user to go back and forth using the keys a and d, w and s are commented out

  1. // ==UserScript==
  2. // @name chess.com, wasd controls
  3. // @description allows user to go back and forth using the keys a and d, w and s are commented out
  4. // @version 1.2
  5. // @author Tobias L
  6. // @include *.chess.com/*
  7. // @license GPL-3.0-only
  8. // @namespace https://github.com/WhiteG00se/User-Scripts
  9. // ==/UserScript==
  10.  
  11. function simulateKeyPress(key) {
  12. let keyPress = new KeyboardEvent('keydown', {
  13. key: key,
  14. code: key,
  15. bubbles: true,
  16. cancelable: true,
  17. view: window,
  18. })
  19. document.dispatchEvent(keyPress)
  20. }
  21.  
  22. document.body.addEventListener('keydown', function (event) {
  23. switch (event.key) {
  24. // case 'w':
  25. // simulateKeyPress('ArrowUp')
  26. // break
  27. case 'a':
  28. simulateKeyPress('ArrowLeft')
  29. break
  30. // case 's':
  31. // simulateKeyPress('ArrowDown')
  32. // break
  33. case 'd':
  34. simulateKeyPress('ArrowRight')
  35. break
  36. }
  37. })