test
This commit is contained in:
+12
-18
@@ -1,37 +1,31 @@
|
||||
const { execSync } = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
const POWER_SHELL = 'powershell -NoProfile -Command';
|
||||
const SCRIPT = path.join(__dirname, 'send-move.ps1');
|
||||
const PS = `powershell -NoProfile -ExecutionPolicy Bypass -File "${SCRIPT}"`;
|
||||
|
||||
function getMousePos() {
|
||||
const cmd = `${POWER_SHELL} "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Cursor]::Position"`;
|
||||
const output = execSync(cmd, { windowsHide: true }).toString();
|
||||
const match = output.match(/(\d+)\s+(\d+)\s*$/m);
|
||||
if (!match) throw new Error('Failed to get mouse position: ' + output);
|
||||
return { x: parseInt(match[1], 10), y: parseInt(match[2], 10) };
|
||||
}
|
||||
|
||||
function setMousePos(x, y) {
|
||||
const cmd = `${POWER_SHELL} "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(${x}, ${y})"`;
|
||||
execSync(cmd, { windowsHide: true });
|
||||
function moveMouse(dx) {
|
||||
execSync(`${PS} ${dx}`, { windowsHide: true });
|
||||
}
|
||||
|
||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
async function main() {
|
||||
console.log('已启动防息屏,每 15 秒移动鼠标 1 像素再移回原位。Ctrl+C 停止。\n');
|
||||
console.log('已启动防息屏,每 15 秒触发真实鼠标事件(SendInput)。Ctrl+C 停止。\n');
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('\n已停止。');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
let tick = 0;
|
||||
while (true) {
|
||||
const orig = getMousePos();
|
||||
setMousePos(orig.x + 1, orig.y);
|
||||
console.log(`→ 右移 1 像素 (${orig.x}, ${orig.y}) → (${orig.x + 1}, ${orig.y})`);
|
||||
tick++;
|
||||
moveMouse(1);
|
||||
console.log(`【${tick}】→ 右移 1 像素 (SendInput)`);
|
||||
await sleep(14000);
|
||||
setMousePos(orig.x, orig.y);
|
||||
console.log(`← 移回原位 (${orig.x + 1}, ${orig.y}) → (${orig.x}, ${orig.y})`);
|
||||
moveMouse(-1);
|
||||
console.log(`【${tick}】← 移回原位 (SendInput)`);
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user