javascript - 键盘事件可以更快吗?
问题描述
我正在尝试为网站制作自动点击器,但自动点击器只有 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
解决方案
我不知道正在捕获哪个网站以及如何捕获,但这里有一个可以运行的小板凳:
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>
推荐阅读
- android - 由于 SDK 导致 Google Play 应用更新被拒绝,但并未真正包含在内
- c++ - 类 std::result_of 中没有名为“类型”的类型
- node.js - MongoDB 不会推送到数组
- javascript - 如何在 MongoDB 中自定义增量 ID 或数字?
- ios - UITableViewCell 高度根据行内容使用自动布局动态计算
- haskell - 函数重载
- c++ - 在 Ubuntu 中使用 clang 编译 c++17 代码时找不到 string_view
- swift - 在不创建新 UIImage/CGImage 的情况下更改 UIImage 的一个像素的颜色
- centos - ImageMagick - 在 ubuntu 而不是 centos 上工作的命令
- dropdown - 如何创建自动更新依赖下拉列表?