键盘邦邦

嘤嘤嘤

  1. // ==UserScript==
  2. // @name 键盘邦邦
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 嘤嘤嘤
  6. // @author flaribbit
  7. // @match https://bangplayer.live/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. var skeys = "zxcvbnm";
  15. var keys = {};
  16. var keydown = {};
  17. for (var i = 0; i < 7; i++) {
  18. keys[skeys[i]] = i - 3;
  19. keydown[skeys[i]] = false;
  20. }
  21.  
  22. function getKeyPos(key) {
  23. var gamecanvas = document.querySelector("#game");
  24. var keyposy = 0;
  25. var width = gamecanvas.height * 16 / 9;
  26. if (width > gamecanvas.width) {
  27. //太高了
  28. width = gamecanvas.width;
  29. keyposy = 0.5 * gamecanvas.height + 0.38 * width * 9 / 16;
  30. } else {
  31. //太宽了
  32. keyposy = gamecanvas.height * 0.88;
  33. }
  34. width /= 8.4;
  35. return { clientX: Math.round(gamecanvas.width / 2 + width * keys[key]), clientY: keyposy }
  36. }
  37. document.onkeydown = function (e) {
  38. if (e.key in keys) {
  39. if (keydown[e.key] == false) {
  40. document.querySelector("#game").dispatchEvent(new PointerEvent("pointerdown", getKeyPos(e.key)));
  41. console.log("按下", e.key);
  42. }
  43. keydown[e.key] = true;
  44. }
  45. }
  46. document.onkeyup = function (e) {
  47. if (e.key in keys) {
  48. document.querySelector("#game").dispatchEvent(new PointerEvent("pointerup", getKeyPos(e.key)));
  49. console.log("松开", e.key);
  50. keydown[e.key] = false;
  51. }
  52. }
  53. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址