请教模拟鼠标点击如后后台运行?

8608074 1天前 65

下面代码实现鼠标自动点击,运行时就不能干其他事情啦

timer.onTimer = function(句柄,msg,id,tick){
	var  offset = tonumber(winform.偏移设置.text);//偏移量
	for(i=1;#坐标列表;1) {
                    // 生成随机偏移                   
                    var  targetX = 坐标列表[i].x + math.random(-offset, offset);
                    var  targetY = 坐标列表[i].y + math.random(-offset, offset);
                   // win.msgbox(坐标列表[i])
                    // 移动并点击
                   // mouse.setPos(targetX, targetY,true);
                    win.delay(100);
                    mouse.click(targetX, targetY,true);                   
                    // 随机延迟
                    win.delay(坐标列表[i].延迟量 + math.random(-20, 20));
                }
}

下面这样改,没有反应,不知道哪里错了

// 定义坐标结构体var pt = {
    int x = globalX; // 全局坐标X
    int y = globalY; // 全局坐标Y}
    // 转换坐标到窗口客户区
    ::User32.ScreenToClient(hwnd, pt); 
    // 组合 LPARAM 参数
    var lParam = (pt.y << 16) | (pt.x & 0xFFFF);
    // 发送鼠标左键按下消息
    ::User32.SendMessage(hwnd, 0x201/*_WM_LBUTTONDOWN*/, 0x1/*_MK_LBUTTON*/, lParam);

请大佬们看看,能不能实现模拟鼠标后台点击不影响其他工作/

最新回复 (1)
  • 8608074 12小时前
    0 2
    搞定了,句柄要子窗口句柄,鼠标按下了还要松开 // 转换坐标到窗口客户区 ::User32.ScreenToClient(hwnd, pt); // 组合 LPARAM 参数 var lParam = (pt.y << 16) | (pt.x & 0xFFFF); // 发送鼠标左键按下消息 ::User32.PostMessage(hwnd, 0x201/*_WM_LBUTTONDOWN*/, 0x1/*_MK_LBUTTON*/, lParam); win.delay(50); ::User32.PostMessage(hwnd, 0x202, 0, lParam);
返回
发新帖