首页 > 解决方案 > 键盘事件可以更快吗?

问题描述

我正在尝试为网站制作自动点击器,但自动点击器只有 400 cps 我想看看它是否可以更快

var event = new KeyboardEvent('keydown',{key:'g',
    ctrlKey:true
});

setInterval(function(){
   for(i=0; i< 100; i++){
     document.dispatchEvent(event);
   }
}, 0); 2256
256

标签: javascript

解决方案


我不知道正在捕获哪个网站以及如何捕获,但这里有一个可以运行的小板凳:

let sent = 0,
  received = 0,
  pack = 100,
  date = new Date().getTime(),
  stop = false,
  timer;

document.addEventListener("keydown", e => {
  if (++received > 1000000)
    stop = true;

  if (!(received % ((pack * 100 < 10000 ? pack *100 : 10000)))) {
    const time = (new Date().getTime() - date);
    console.log("sent:" + sent, "received:" + received, "Pack:" + pack, (pack * 100 < 10000 ? pack *100 : 10000), "Time:" + time, "CPS:" + ~~(received / time * 1000));
  }
});
var event = new KeyboardEvent('keydown', {
  key: 'g',
  ctrlKey: true
});

function init()
{
  document.querySelector("button").textContent=stop?'START':'STOP';
  document.querySelector("select").value = pack;
  received = sent = 0;
  date = new Date().getTime();
  clearInterval(timer);
  if (stop)
    return;

  timer = setInterval(function() {
    if (stop)
      return init();

    for (let i = 0; i < pack; i++) {
      sent++;
      document.dispatchEvent(event);
    }
  }, 0);
}
init();
<button onclick="stop=!stop;init()"></button>
<select oninput="pack=this.value;init()">
  <option value="1">1</option>
  <option value="10">10</option>
  <option value="100" selected>100</option>
  <option value="1000">1000</option>
  <option value="10000">10000</option>
  <option value="100000">100000</option>
</select>


推荐阅读