Lua 随机鼠标左键连点脚本 - Windows 自动点击工具
以下是一个实现鼠标左键随机连点的 Lua 脚本示例:
-- 导入库
local ffi = require("ffi")
-- 定义鼠标左键常量
ffi.cdef[[typedef struct tagINPUT {uint32_t type;union {struct {int32_t dx;int32_t dy;uint32_t mouseData;uint32_t dwFlags;uint32_t time;void* dwExtraInfo;} mi;uint32_t ki;uint32_t hi;} ;} INPUT;typedef struct tagPOINT {int32_t x;int32_t y;} POINT;typedef struct tagRECT {int32_t left;int32_t top;int32_t right;int32_t bottom;} RECT;void* GetDC(void* hWnd);int32_t GetClientRect(void* hWnd, RECT* lpRect);int32_t ClientToScreen(void* hWnd, POINT* lpPoint);int32_t SendInput(uint32_t nInputs, INPUT* pInputs, int32_t cbSize);int32_t ReleaseDC(void* hWnd, void* hDC);]]
local user32 = ffi.load("user32")
-- 获取窗口句柄
local hWnd = user32.GetForegroundWindow()
-- 获取窗口客户区矩形
local rect = ffi.new("RECT")
user32.GetClientRect(hWnd, rect)
-- 计算窗口客户区左上角和右下角坐标
local topLeft = ffi.new("POINT", rect.left, rect.top)
local bottomRight = ffi.new("POINT", rect.right, rect.bottom)
user32.ClientToScreen(hWnd, topLeft)
user32.ClientToScreen(hWnd, bottomRight)
-- 定义连点次数和延迟时间范围
local clickCount = 10
local delayMin = 100 -- 最小延迟时间(毫秒)
local delayMax = 500 -- 最大延迟时间(毫秒)
-- 随机连点
for i = 1, clickCount do
-- 随机生成延迟时间
local delay = math.random(delayMin, delayMax)
-- 随机生成点击位置
local x = math.random(topLeft.x, bottomRight.x)
local y = math.random(topLeft.y, bottomRight.y)
-- 设置鼠标位置
ffi.C.SetCursorPos(x, y)
-- 模拟鼠标按下和抬起
local inputDown = ffi.new("INPUT", {type = 0, mi = {dx = 0, dy = 0, dwFlags = 2}})
local inputUp = ffi.new("INPUT", {type = 0, mi = {dx = 0, dy = 0, dwFlags = 4}})
user32.SendInput(2, ffi.new("INPUT[2]", {inputDown, inputUp}), ffi.sizeof("INPUT"))
-- 延迟指定时间
os.execute("timeout " .. delay / 1000)
end
请注意,该脚本使用了 Windows API 来模拟鼠标操作,因此仅适用于 Windows 操作系统。在运行脚本之前,你需要安装 LuaJIT 并将其添加到系统路径中。
脚本功能:
- 随机生成点击位置
- 随机生成点击延迟时间
- 模拟鼠标左键按下和抬起动作
- 可自定义点击次数和延迟时间范围
使用方法:
- 将脚本保存为
.lua文件。 - 确保已安装 LuaJIT 并将其添加到系统路径中。
- 在命令行中运行脚本:
luajit your_script.lua。
注意:
- 该脚本仅用于学习和研究目的,请勿用于任何非法活动。
- 在使用脚本前,请确保已备份重要数据。
- 使用脚本造成的任何损失,本人概不负责。
原文地址: https://www.cveoy.top/t/topic/p8jw 著作权归作者所有。请勿转载和采集!