其他分享
首页 > 其他分享> > 2021Autojs快手自动挂机抢最新实战分享

2021Autojs快手自动挂机抢最新实战分享

作者:互联网

此代码由日赚3万网autojs开发交流群整理提供,欢迎大家一起技术交流,查看更多脚本和源码: 点击一键加群。如有侵权,请联系我删除!

// 单机收益20+,可批量操作。
auto();
//设置按键监听 当脚本执行时候按音量减 退出脚本
function registEvent() {
    //启用按键监听
    events.observeKey();
    //监听音量上键按下
    events.onKeyDown("volume_down", function (event) {
        tLog("脚本手动退出");
        exit();
    });
}


threads.start(function () {
    var 立即开始;
    if (立即开始 = classNameContains("Button").textContains("立即开始").findOne(2000)) {
        sleep(300)
        立即开始.click()
    } else {
        var 允许;
        if (允许 = classNameContains("Button").textContains("允许").findOne(2000)) {
            sleep(300)
            允许.click()
        }
    }
});



if (!requestScreenCapture()) {
    toast("请求截图失败");
    exit();
}



// 设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标
// setScreenMetrics(1080, 1920);
// 设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标

function getStorage(key) {
    var storage = storages.create("cn.iqunkong.demo:Test");
    return storage.get(key);
}




//悬浮窗

//脚本全部参数设置完毕!显示开始悬浮窗
var w = floaty.window(<vertical alpha="0.9">






    <card w="*" h="32" bg="#333333" gravity="center_vertical"><vertical h="auto" padding="7 0 5 0">

        <text id="zs" text="抢 0 次" textColor="#FFFFFF" />

    </vertical>

        <View bg="#F44336" w="2" h="*" /></card>




    <card w="*" h="32" bg="#333333" gravity="center_vertical"><vertical h="auto" padding="7 0 5 0">

        <text id='cg' text='成 0 次' textColor="#FFFFFF" />

    </vertical>

        <View bg="#4CAF50" w="2" h="*" /></card>




    <card w="*" h="32" bg="#F44336" gravity="center_vertical"><vertical h="auto" padding="7 0 5 0">

        <text id="ggbb" text="退出脚本" textColor="#FFFFFF" />

    </vertical>

        <View bg="#F44336" w="2" h="*" /></card>



    <card w="*" h="32" bg="#4CAF50" gravity="center_vertical"><vertical h="auto" padding="7 0 5 0">

        <text id='wz' text='移动位置' textColor="#FFFFFF" />

    </vertical>

        <View bg="#4CAF50" w="2" h="*" /></card>



    <card w="*" h="32" bg="#0096ff" gravity="center_vertical"><vertical h="auto" padding="7 0 5 0">

        <text id='ok' text='' textColor="#FFFFFF" />

    </vertical>

        <View bg="#0096ff" w="2" h="*" /></card>


</vertical>);

//悬浮窗关闭时自动停止脚本
w.exitOnClose();

//悬浮窗常在
setInterval(() => { }, 1000);

// 设置为-2则为根据悬浮窗内容大小而定
w.setSize(-2, -2);


//设置悬浮窗的位置
w.setPosition(0, device.height * 0.38);


w.wz.click(() => {
    w.setAdjustEnabled(!w.isAdjustEnabled());
});



//定义安妮判断变量
var state = 0;
ui.run(function () {
    w.ok.setText('开始运行');
});





//悬浮窗ok按钮单击事件
w.ok.on('click', () => {
    if (state == 0) {
        log('开始运行');
        ui.run(function () {
            w.ok.setText('暂停运行');
        });
        state = 1;


        threads.start(function () {
            快手自动红包()
        });

        threads.start(function () {
            广告()
        });
        pd = threads.start(function () {
            是否一致()
        });

        //开始执行线程  

    } else {
        log('暂停运行');

        ui.run(function () {
            w.ok.setText('开始运行');
        });

        //是否开启线程,如果开启则关闭 


        threads.shutDownAll();//退出所有线程


        state = 0;

    }
});
//悬浮窗ok按钮单击事件



//悬浮窗ggbb按钮单击事件
w.ggbb.on('click', () => {
    exit();
});
//悬浮窗ggbb按钮单击事件




//悬浮窗






///动态悬浮文字
var window = floaty.window(<vertical alpha="0.8">
    <frame gravity="center">
        <text id="text" textSize="16sp" textColor="#f8f8f8" bg="#090909" />
    </frame>

</vertical>);


window.text.click(() => {
    window.setAdjustEnabled(!window.isAdjustEnabled());
});

setInterval(() => {
    //对控件的操作需要在UI线程中执行
    ui.run(function () {
        window.text.setText(dynamicText());
    });
}, 1000);

function dynamicText() {
    var date = new Date();
    // var str = util.format("内存使用量: %d%%\n", getMemoryUsage());
    // str += util.format("时间: %d:%d:%d\n", date.getHours(), date.getMinutes(), date.getSeconds());
    var str = "  全自动挂机抢红包辅助  \n";
    // str += "  KUKO作者Q/V:97909029  ";
    return str;
}

//获取内存使用率
function getMemoryUsage() {
    var usage = (100 * device.getAvailMem() / device.getTotalMem());
    //保留一位小数
    return Math.round(usage * 10) / 10;
}
//动态悬浮文字



var 秒 = 3

var 极速版 = 读配置("KUKO", "极速版", true)

var 正常版 = 读配置("KUKO", "正常版", true)

var 随机关注 = 读配置("KUKO", "随机关注", true)

var 不关注 = 读配置("KUKO", "不关注", true)



var 总数 = 1
var 成功 = 0

function 广告() {

    while (true) { ///无限循环

        if (text("关闭应用").findOne(1000)) {
            sleep(100)
            click("关闭应用")
        } else {
            if (text("确定").exists()) {
                sleep(100)
                click("确定")
            } else {
                if (text("取消").exists()) {
                    sleep(100)
                    click("取消")
                } else {
                    if (id("live_audience_new_profile_more").exists() || id("photo_feed_side_bar_close_view").exists() || desc("更多").exists() || text("继续加油").exists()|| text("本次未被抽中").exists() || text("好友推荐").exists() || text("马上绑定").exists() || text("发送").exists() || text("知道了").exists() || text("立即领取").exists() || text("预计24小时内到账").exists() || text("以后再说").exists() || text("本次未中奖").exists() || text("正在开奖").exists()) {//推荐和个人资料
                        sleep(100)
                        back()
                    } else {
                        if (text("我先围观").exists()) {
                            sleep(100)
                            click("我先围观")
                        } else {

                            if (正常版 == true) {

                                if (currentPackage() != "com.smile.gifmaker") {//包名
                                    sleep(100)
                                    launchApp("快手");
                                }

                            } else {
                                if (极速版 == true) {
                                    if (currentPackage() != "com.kuaishou.nebula") {//包名
                                        sleep(100)
                                        launchApp("快手极速版");
                                    }
                                }
                            }




                        }
                    }
                }

            }
        }




    }
}

function 是否一致() {///判断5分钟内后图片是否一致
    while (true) { ///无限循环


        var 原图 = images.clip(captureScreen(), device.width / 3, device.height / 3, 320, 130)//区域截图
        sleep(5 * 60000)
        var 截图 = captureScreen()
        var 对比 = findImage(截图, 原图, {
            region: [device.width / 3, device.height / 3, 320, 130],//前面2个是初始坐标,后面2个是后面的坐标减初始坐标
            threshold: 0.95 //相识度
        });
        if (对比) {
            if (id("close_icon_view").exists()) {//是否有返回
                sleep(100)
                id("close_icon_view").findOne().click()
            }

            log("图片一样")

            threads.shutDownAll();//退出所有线程
            threads.start(function () {
                快手自动红包()
            });

            threads.start(function () {
                广告()
            });
            pd = threads.start(function () {
                是否一致()
            });

            //开始执行线程  




        } else {
            log("图片不一样")
        }

    }
}


function 快手自动红包() {

    if (正常版 == true) {//红包是否存在
        sleep(100)
        launchApp("快手");
    } else {
        sleep(100)
        launchApp("快手极速版");
    }


    while (true) { ///无限循环


        if (text("直播广场").findOne(random(5000, 5800)) || id("left_btn").findOne(random(5000, 5800))) {
            sleep(100)
            click("直播广场")
        } else {

            if (id("live_red_packet_status_text").exists()) {//红包是否存在
                sleep(100)
                var 总时间 = id("live_red_packet_status_text").findOne().text()//获取红包时间

                if (总时间 != "抢红包") {
                    var 分1 = /(.*):/;
                    var 秒1 = /[0-9]:(.*)/;
                    var 分 = 分1.exec(总时间)[1]
                    var 秒 = 秒1.exec(总时间)[1]

                    if (分 <= 1 && 秒 <= 59) { //检测是否有倒计
                        if (id("live_red_packet_avatar").findOne(2000)) {//1分钟之内
                            sleep(100)
                            id("live_red_packet_avatar").findOne().parent().parent().parent().click()//通过父控件点击红包
                            快手开抢()
                            break
                        } else {
                            if (id("live_red_packet_container_close_view").exists()) {//关了
                                sleep(100)
                                id("live_red_packet_container_close_view").findOne().click()//关了     
                            }

                            //开始下滑
                            var x1 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                            var y1 = random((device.height / 4) * 1.38, (device.height / 4) * 1.39);
                            var x2 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                            var y2 = random(device.height, device.height);
                            RandomSwipe(x1, y1, x2, y2, random(200, 300));
                            //开始下滑


                        }

                    } else {
                        if (id("live_red_packet_container_close_view").exists()) {//关了
                            sleep(100)
                            id("live_red_packet_container_close_view").findOne().click()//关了
                        }

                        //开始下滑
                        var x1 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                        var y1 = random((device.height / 4) * 1.38, (device.height / 4) * 1.39);
                        var x2 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                        var y2 = random(device.height, device.height);
                        RandomSwipe(x1, y1, x2, y2, random(200, 300));
                        //开始下滑


                    }
                } else {
                    toast("确定抢不到")
                    if (id("live_red_packet_container_close_view").exists()) {//关了
                        sleep(100)
                        id("live_red_packet_container_close_view").findOne().click()//关了
                    }

                    //开始下滑
                    var x1 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                    var y1 = random((device.height / 4) * 1.38, (device.height / 4) * 1.39);
                    var x2 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                    var y2 = random(device.height, device.height);
                    RandomSwipe(x1, y1, x2, y2, random(200, 300));
                    //开始下滑
                }




            } else {
                toast("没有红包")
                if (id("live_red_packet_container_close_view").exists()) {//关了
                    sleep(100)
                    id("live_red_packet_container_close_view").findOne().click()//关了
                }
                
                //开始下滑
                var x1 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                var y1 = random((device.height / 4) * 1.38, (device.height / 4) * 1.39);
                var x2 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                var y2 = random(device.height, device.height);
                RandomSwipe(x1, y1, x2, y2, random(200, 300));
                //开始下滑



            }

        }


    }
}



function 快手开抢() {

    while (true) { ///无限循环

        if (id("live_red_pack_count_down_second_text_view").findOne(2000)) {//判断红包时间是否存在
            sleep(100)
            var 大红包时间 = id("live_red_pack_count_down_second_text_view").findOne().text()//获取红包时间


            if (id("live_red_pack_snatch_view").findOne(2000)) {//判断红包时间是否存在
                sleep(100)
                var 大包坐标 = id("live_red_pack_snatch_view").findOne().bounds(); //获取ID组件坐标位置
                // textStartsWith("10").findOne().text()   提取text包含10的全部内容
            }
            if (大红包时间 <= 秒) { //检测是否有倒计
                for (var yyy = 0; yyy < 36; yyy++) {
                    click(大包坐标.centerX() + random(-10, 10), 大包坐标.centerY() + random(-10, 10)); //点击ID组件坐标位置
                }

            }

        } else {

            if (id("live_condition_red_packet_panel_current_info_tip_container").exists()) {
                sleep(100)
                if (id("live_red_packet_container_close_view").exists()) {//关了
                    sleep(100)
                    id("live_red_packet_container_close_view").findOne().click()//关了
                }

                //开始下滑
                var x1 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                var y1 = random((device.height / 4) * 1.38, (device.height / 4) * 1.39);
                var x2 = random((device.width / 4) * 2, (device.width / 4) * 2.1);
                var y2 = random(device.height, device.height);
                RandomSwipe(x1, y1, x2, y2, random(1000, 1300));
                //开始下滑

            } else {
                总数++
                ui.run(function () {
                    w.zs.setText("抢" + 总数 + "次");

                })
                抢完()
                break
            }


        }
    }

}




function 抢完() {

    while (true) { ///无限循环
        if (id("live_red_pack_lucky_users_tittle_text_view").findOne(2000) || text("全部送给主播").findOne(2000)) {//判断是否抢到

            成功++
            ui.run(function () {
                w.cg.setText("成" + 成功 + "次");
            })

            if (id("live_red_packet_container_close_view").findOne(1000)) {//关了
                id("live_red_packet_container_close_view").findOne().click()//关了
            }
        } else {
            if (id("live_red_packet_container_close_view").findOne(1000)) {//关了
                id("live_red_packet_container_close_view").findOne().click()//关了
            }
            快手自动红包()
            break

        }
    }
}





function 写配置(文件名, 键, 值) {
    const storage = storages.create(文件名)
    storage.put(键, 值)
}

function 读配置(文件名, 键, 默认值) {
    const storage = storages.create(文件名);
    if (storage.contains(键)) {
        return storage.get(键, 默认值);
    };
    写配置(文件名, 键, 默认值)
    return 默认值
}



//-------------------------曲线滑动-----------------------------//
/**
 * 仿真随机带曲线滑动(视频/小说)
 * @param {起点x} qx 
 * @param {起点y} qy 
 * @param {终点x} zx 
 * @param {终点y} zy 
 * @param {过程耗时单位毫秒} time 
 */
function RandomSwipe(qx, qy, zx, zy, time) {
    var xxy = [time];
    point = [];
    var dx0 = {
        "x": qx,
        "y": qy
    };
    var dx1 = {
        "x": random(qx - (device.width / 4) * 0.25, qx + (device.width / 4) * 0.25),
        "y": random(qy, qy + 50)
    };
    var dx2 = {
        "x": random(zx - (device.width / 4) * 0.25, zx + (device.width / 4) * 0.25),
        "y": random(zy, zy + 50)
    };
    var dx3 = {
        "x": zx,
        "y": zy
    };
    for (var i = 0; i < 4; i++) {
        eval("point.push(dx" + i + ")");
    };
    for (var i = 0; i < 1; i += 0.08) {
        xxyy = [parseInt(bezier_curves(point, i).x), parseInt(bezier_curves(point, i).y)]
        xxy.push(xxyy);
    }
    gesture.apply(null, xxy);
};

function bezier_curves(cp, t) {
    cx = 3.0 * (cp[1].x - cp[0].x);
    bx = 3.0 * (cp[2].x - cp[1].x) - cx;
    ax = cp[3].x - cp[0].x - cx - bx;
    cy = 3.0 * (cp[1].y - cp[0].y);
    by = 3.0 * (cp[2].y - cp[1].y) - cy;
    ay = cp[3].y - cp[0].y - cy - by;

    tSquared = t * t;
    tCubed = tSquared * t;
    result = {
        "x": 0,
        "y": 0
    };
    result.x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
    result.y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
    return result;
};
//-------------------------曲线滑动-----------------------------//




//-------------------------拖动滑块-----------------------------//
/**
 * 拖动滑块
 */
function 过滑块() {
    for (var i = 0; i < 0; i++) { sleep(1000); log(i); }
    while (true) {
        img = images.captureScreen();
        if (img) {
            console.log("截图成功。进行识别滑块!");
            break;
        } else {
            console.log('截图失败,重新截图');
        }
    }
    var zx = discernSlidingblock(img, device.width) + 65
    console.info("识别结果滑块X坐标:" + zx);
    if (zx > -1) {
        //计算拖到滑块坐标
        var 向右拖动滑块填充拼图 = text("向右拖动滑块填充拼图").findOne();
        var qx = 向右拖动滑块填充拼图.bounds().left + (向右拖动滑块填充拼图.bounds().width() * 0.15) / 2;
        var qy = 向右拖动滑块填充拼图.bounds().centerY();
        var zy = qy;
        console.log(qx);
        console.log(qy);
        DragSliderSwipe(qx, qy, zx, zy)
        return true;
    } else {
        console.log("识别有误,请确认是否在滑块界面");
        return false;
    }
}
/**
 * 计算滑块位置
 * @param {图片} img 
 * @param {分辨率} ratio 
 */
function discernSlidingblock(img, ratio) {
    //创建识别变量
    var temp, temp2, x, y, num, color, p, temp3, arr1;
    //分析设备分辨率
    if (ratio == 720) {
        var tb = [348, 253, 691, 638, 81]
        log("您的设备分辨率为:720p");
    } else if (ratio == 1080) {
        var tb = [463, 387, 912, 831, 125]
        log("您的设备分辨率为:1080p");
    } else {
        log("当前设备分辨率不符合规范")
        return -2
    }
    num = Math.ceil(tb[4] / 3.3 - 4);

    //计算滑块位置
    for (var k = 29; k <= 40; k++) {
        temp2 = "";
        color = "#" + k + "" + k + "" + k + "";
        for (var i = 1; i <= num; i++) {
            temp2 = temp2 + "0|" + i + "|" + color + ",";
            temp2 = temp2 + i + "|0|" + color + ",";
            temp2 = temp2 + "1|" + i + "|" + color + ",";
            temp2 = temp2 + i + "|1|" + color + ",";
            temp2 = temp2 + "2|" + i + "|" + color + ",";
            temp2 = temp2 + i + "|2|" + color + ",";
        }
        x = 0;
        while (x > -2) {
            y = 0;
            while (y > -2) {
                temp = "";
                for (var i = 1; i <= num; i += 2) {
                    temp = temp + "0|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x) + "|" + i + "|" + color + ",";
                    temp = temp + (tb[4] + x) + "|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|0|" + color + ",";
                    temp = temp + i + "|" + (tb[4] + y) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|" + (tb[4] + y) + "|" + color + ",";
                    temp = temp + "1|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - 1) + "|" + i + "|" + color + ",";
                    temp = temp + (tb[4] + x - 1) + "|" + (tb[4] + y - i - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|1|" + color + ",";
                    temp = temp + i + "|" + (tb[4] + y - 1) + "|" + color + ",";
                    temp = temp + (tb[4] + x - i - 1) + "|" + (tb[4] + y - 1) + "|" + color + ",";
                }
                temp = temp + temp2 + "0|0|" + color;
                arr1 = temp.split(",");
                var arr2 = new Array();
                for (var i = 0; i < arr1.length - 1; i++) {
                    arr2[i] = new Array();
                    temp3 = arr1[i].split("|");
                    arr2[i] = [Number(temp3[0]), Number(temp3[1]), temp3[2]];
                }
                try {
                    p = images.findMultiColors(img, color, arr2, {
                        region: [tb[0], tb[1], tb[2] - tb[0], tb[3] - tb[1]],
                        threshold: (Math.floor(k / 10) * 16 + k % 10)
                    });
                    if (p) {
                        img.recycle();
                        return p.x
                    }
                } catch (error) {
                    //出错
                    console.log("识别失败,错误原因:" + error);
                    return -1;
                }
                y = --y;
            }
            x = --x;
        }
    }
    try {
        img.recycle();
    } catch (error) {
        console.log("识别失败,错误原因:" + error);
    }
    return -1;
}
/**
 * 真人模拟滑动函数 (滑块滑动)
 * @param {起点x} sx 
 * @param {起点y} sy 
 * @param {终点x} ex 
 * @param {终点y} ey 
 */
function DragSliderSwipe(sx, sy, ex, ey) {
    //设置随机滑动时长范围
    var timeMin = 1000
    var timeMax = 3000
    //设置控制点极限距离
    var leaveHeightLength = 500

    //根据偏差距离,应用不同的随机方式
    if (Math.abs(ex - sx) > Math.abs(ey - sy)) {
        var my = (sy + ey) / 2
        var y2 = my + random(0, leaveHeightLength)
        var y3 = my - random(0, leaveHeightLength)

        var lx = (sx - ex) / 3
        if (lx < 0) { lx = -lx }
        var x2 = sx + lx / 2 + random(0, lx)
        var x3 = sx + lx + lx / 2 + random(0, lx)
    } else {
        var mx = (sx + ex) / 2
        var y2 = mx + random(0, leaveHeightLength)
        var y3 = mx - random(0, leaveHeightLength)

        var ly = (sy - ey) / 3
        if (ly < 0) { ly = -ly }
        var y2 = sy + ly / 2 + random(0, ly)
        var y3 = sy + ly + ly / 2 + random(0, ly)
    }
    //获取运行轨迹,及参数
    var time = [0, random(timeMin, timeMax)]
    var track = bezierCreate(sx, sy, x2, y2, x3, y3, ex, ey)
    // log("随机控制点A坐标:" + x2 + "," + y2)
    // log("随机控制点B坐标:" + x3 + "," + y3)
    // log("随机滑动时长:" + time[1])
    //滑动
    gestures(time.concat(track))
}
/**
 * 计算滑动轨迹
 */
function bezierCreate(x1, y1, x2, y2, x3, y3, x4, y4) {
    //构建参数
    var h = 100;
    var cp = [{ x: x1, y: y1 + h }, { x: x2, y: y2 + h }, { x: x3, y: y3 + h }, { x: x4, y: y4 + h }];
    var numberOfPoints = 100;
    var curve = [];
    var dt = 1.0 / (numberOfPoints - 1);
    //计算轨迹
    for (var i = 0; i < numberOfPoints; i++) {
        var ax, bx, cx;
        var ay, by, cy;
        var tSquared, tCubed;
        var result_x, result_y;

        cx = 3.0 * (cp[1].x - cp[0].x);
        bx = 3.0 * (cp[2].x - cp[1].x) - cx;
        ax = cp[3].x - cp[0].x - cx - bx;
        cy = 3.0 * (cp[1].y - cp[0].y);
        by = 3.0 * (cp[2].y - cp[1].y) - cy;
        ay = cp[3].y - cp[0].y - cy - by;

        var t = dt * i
        tSquared = t * t;
        tCubed = tSquared * t;
        result_x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
        result_y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
        curve[i] = {
            x: result_x,
            y: result_y
        };
    }
    //轨迹转路数组
    var array = [];
    for (var i = 0; i < curve.length; i++) {
        try {
            var j = (i < 100) ? i : (199 - i);
            xx = parseInt(curve[j].x)
            yy = parseInt(Math.abs(100 - curve[j].y))
        } catch (e) {
            break
        }
        array.push([xx, yy])
    }
    return array
}

//-------------------------拖动滑块-----------------------------//

标签:function,快手,text,random,device,var,cp,挂机,2021Autojs
来源: https://blog.csdn.net/qq_29117491/article/details/118650995