| 
                                        
                                     
                                        
                                        大学三年级325019814131826 朵2969 个940 个206002009-10-23 | 
                                        
                                            
                                                
                                                1#
                                                
                                            
                                        
                                        
                                            
                                                
                                                
                                                t
                                                T
                                            发表于 2022-02-19 17:19
                                            
                                                                                        
                                            | 
                                            
                                            
                                            |只看楼主 
                    
                    
                    
                   
                    
                        
                        
                        大家好,我是公众号3分钟学堂的郭立员~ 做按键精灵安卓版教程有好几年了,有时候我在想按键脚本有啥用?它的最大作用就是代替人完成重复性的操作。 前段时间,大成给我发了一个公众号阅读的平台,就是看文章给钱的,单篇文章收益不高,但是可以重复操作。   看完文章以后把当前文章的阅读数发给平台就可以获得收益了。 一个小时阅读文章上限是25篇,粗略算一下单台设备一天几块钱。 我不是专门做阅读赚钱的,手里没有那么多设备和微信,所以收益多少对我来说也不重要。 今天主要来说说写脚本的过程中的一些体会~这个脚本我写了两个思路:思路一: 按照脚本手动操作逻辑,一步步操作,这也是平时大家写脚本的常用思路。 比如:先点击按钮,等待2秒钟时间,然后进入另外一个页面,接下来滑动页面,找图、输入文字等等一些操作,手动咋操作,脚本就写上对应的命令。思路二: 让脚本稍微聪明一点,能够自己辨别当前画面是哪个页面,在这个页面要执行什么操作。 比如:检测到当前页面是A页面,执行a操作,之后在检测页面是什么页面,如果是B页面就执行b操作,如果是C页面执行c操作。。。 这个思路的优点是每一次都“校对”当前页面是什么页面,不会出现脚本和app不同步发生错乱的情况。 缺点也很明显就是每次都要校对所有的页面。 下面给大家看看我写的代码: 代码仅供学习参考,因为都是图色命令,你复制也没法用,而且也没有找图的附件图片。 复制代码/*------加载插件-------*/
Import "shanhai.lua"
/*---------定义全局变量--------*/
Dim intx,inty
/*-------主体--------*/
file.Write("/sdcard/pictures/阅读数.txt")
file.Write ("/sdcard/pictures/返回.txt",0)
ShanHai.WeiXinUrl("com.tencent.mm","https://moon.baohe.site?recommend=USER58414478943436300163E0FF9D82")
'判断页面是否打开
Do
    FindPic 0, 0, 0, 0, "Attachment:按钮.png", "000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "阅光宝盒的主页已经打开"
        ShowMessage "阅光宝盒的主页已经打开"
        Delay 3000
        Exit Do
    Else 
        TracePrint "正在加载页面"
        ShowMessage "正在加载页面"
        页面检测_阅读报数()
    End If
    Delay 1000
Loop
For 300
    页面检测_主页() 
    页面检测_阅读报数()
    页面检测_历史消息() 
    页面检测_文章页 
    页面检测_文章列表 
    页面检测_普通阅读 
    Delay 500
Next
/*--------函数--------*/
Function 页面检测_主页()
    Dim intx,inty
    FindPic 0, 0, 0, 0, "Attachment:按钮.png","000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "点击阅ta按钮"
        ShowMessage "点击阅ta按钮"
        Tap intx, inty        
        For i = 1 To 5
            页面检测_歇歇()
            ShowMessage "时间倒计时:" & 5 - i
            Delay 1000
        Next
    End If
End Function
Function 页面检测_阅读报数()
    Dim intx,inty,阅读数
    FindPic 0, 0, 0, 0, "Attachment:阅读报数.png","000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "阅读报数"
        阅读数 = file.read("/sdcard/pictures/阅读数.txt")
        Delay 1000
        If Len(阅读数) > 0 Then 
            Tap 138, 646
            Delay 500
            InputText 阅读数
            Delay 1000
            Tap 363, 746
        Else 
            Tap 177,739
        End If
    End If
End Function
Function 页面检测_历史消息()
    Dim intx,inty
    FindPic 0, 0, 0, 0, "Attachment:历史消息.png","000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "历史消息页面"
        If file.read("/sdcard/pictures/返回.txt") = "0" Then 
            file.Write("/sdcard/pictures/返回.txt",1)
            Tap intx, inty + 90
        Else
            KeyPress "back"
            file.Write ("/sdcard/pictures/返回.txt",0)
        End If
        For i = 1 To 5
            ShowMessage "时间倒计时:" & 5 - i
            Delay 1000
        Next
    End If
End Function
Function 页面检测_文章页()
    Dim intx,inty,text,num,t
    FindPic 0, 0, 0, 0, "Attachment:点.png", "000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        If GetPixelColor(intx, inty+5) = "FFFFFF" Then 
            TracePrint "文章页面"
            ShowMessage "文章页面"
            t=TickCount()
            Do
                FindPic 0, 0, 0, 0, "Attachment:阅读.png|Attachment:阅读2.png|Attachment:观看.png","000000", 0, 0.9, intX, intY
                If intX > -1 And intY > -1 Then 
                    TracePrint "阅读"
                    text = Image.OcrText(intx+43,inty-10,intx+120,inty+24,0,0)
                    num = shanhai.RegexFind(text, "%d+")
                    TracePrint num(0)
                    ShowMessage "用时:"&TickCount() - t
                    If TickCount() - t < 10000 Then 
                        Delay 11000-(TickCount() - t)
                    End If
                    KeyPress "back"
                    file.Write ("/sdcard/pictures/阅读数.txt",num(0))
                    Exit Do
                Else 
                    Swipe 5, 822, 5, 310, 1000
                End If
            Loop
            For i = 1 To 5
                ShowMessage "时间倒计时:" & 5 - i
                Delay 1000
            Next
        End If
        Delay 1000
    End If
End Function
Function 页面检测_文章列表()
    Dim intx,inty
    FindPic 0, 0, 0, 0, "Attachment:文章列表.png","000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "文章列表"
        If file.read("/sdcard/pictures/返回.txt") = "0" Then 
            file.Write("/sdcard/pictures/返回.txt",1)
            Tap 105,457
        Else
            KeyPress "back"
            file.Write ("/sdcard/pictures/返回.txt",0)
        End If
        For i = 1 To 5
            ShowMessage "时间倒计时:" & 5 - i
            Delay 1000
        Next
    End If
End Function
Function 页面检测_普通阅读()
    Dim intx,inty
    FindPic 0, 0, 0, 0, "Attachment:普通阅读.png","000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "普通阅读"
        Tap intx, inty
        For i = 1 To 3
            ShowMessage "时间倒计时:" & 3 - i
            Delay 1000
        Next
    End If
End Function
Function 页面检测_歇歇()
    Dim intx,inty
    FindPic 0, 0, 0, 0, "Attachment:歇歇.png","000000", 0, 0.9, intX, intY
    If intX > -1 And intY > -1 Then 
        TracePrint "休息一下"
        EndScript
    End If
End Function
代码中每一个函数都是独立存在的,而且我尽量使用局部变量,防止函数间冲突,如果涉及到内容的传递,我使用了文本作为媒介。 这些是循环调用的,如下图:   因为每个函数是独立存在的,函数可以随着页面的增加而随时增加,这样维护起来是方便很多。 当然如果页面特别多的时候,页面的检测时间就会比较长了。 对于要操作大量页面的脚本,还是建议使用第一个思路。 这个脚本我在做长时间测试时发现会卡死,我猜测可能是image.ocrtext命令的问题。 今天文章内容不多,主要是提供一个脚本思路,感兴趣的朋友帮忙点个赞!  |