您的位置:首页 > 编程语言 > Python开发

来源于跳一跳python脚本的自动刷百万英雄,芝士超人复活码python脚本!!!!

2018-01-14 21:58 253 查看
import os
import sys
import time
import random
def yes_or_no(prompt, true_value='y', false_value='n', default=True):
default_value = true_value if default else false_value
prompt = '%s %s/%s [%s]: ' % (prompt, true_value, false_value, default_value)
i = input(prompt)
if not i:
return default
while True:
if i == true_value:
return True
elif i == false_value:
return False
prompt = 'Please input %s or %s: ' % (true_value, false_value)
i = input(prompt)
def set_button_position():
global swipe_x11, swipe_y11, swipe_x21, swipe_y21
global swipe_x12, swipe_y12, swipe_x22, swipe_y22
global swipe_x13, swipe_y13, swipe_x23, swipe_y23
global swipe_x14, swipe_y14, swipe_x24, swipe_y24
left1 = int(1000)
top1 = int(1720)
left1 = int(random.uniform(left1-10, left1+10))
top1 = int(random.uniform(top1-10, top1+10))
left2 = int(440)
top2 = int(928)
left2 = int(random.uniform(left2-10, left2+10))
top2 = int(random.uniform(top2-10, top2+10))
left3 = int(150)
top3 = int(837)
left3 = int(random.uniform(left3-10, left3+10))
top3 = int(random.uniform(top3-10, top3+10))
left4 = int(969)
top4 = int(937)
left4 = int(random.uniform(left4-10, left4+10))
top4 = int(random.uniform(top4-10, top4+10))

swipe_x11, swipe_y11, swipe_x21, swipe_y21 = left1, top1, left1, top1
swipe_x12, swipe_y12, swipe_x22, swipe_y22 = left2, top2, left2, top2
swipe_x13, swipe_y13, swipe_x23, swipe_y23 = left3, top3, left3, top3
swipe_x14, swipe_y14, swipe_x24, swipe_y24 = left4, top4, left4, top4
def press():
press_time1=40
press_time2=1000
press_time3=40
press_time3=40

cmd1 = 'adb shell input tap {x11} {y11}'.format(
x11=swipe_x11,
y11=swipe_y11,
)
cmd2 = 'adb shell input swipe {x12} {y12} {x22} {y22} {duration2}'.format(
x12=swipe_x12,
y12=swipe_y12,
x22=swipe_x22,
y22=swipe_y22,
duration2=press_time2
)
cmd3 = 'adb shell input tap {x13} {y13}'.format(
x13=swipe_x13,
y13=swipe_y13,

)
cmd4 = 'adb shell input tap {x14} {y14}'.format(
x14=swipe_x14,
y14=swipe_y14,
)
print(cmd1)
print(cmd2)
print(cmd3)
print(cmd4)
#os.system(cmd1)

os.popen(cmd1,'w')
time.sleep(0.5)
#os.system(cmd2)

os.popen(cmd2,'w')
time.sleep(1.5)
#os.system(cmd3)

os.popen(cmd3,'w')
time.sleep(0.5)
#os.system(cmd4)

os.popen(cmd4,'w')
def main():
op = yes_or_no('请确保手机打开了 ADB 并连接了电脑,然后打开百万英雄再用本程序,确定开始?')
if not op:
print('bye')
return
while True:
set_button_position()
press()
time.sleep(0.5)
if __name__ == '__main__':
main()

本人是在通过学习微信跳一跳python脚本,了解到adb安卓调试工具的作用之后,写下了该脚本。通过打开手机开发者调试,下滑打开指针位置,然后进入百万英雄等界面,分别点击右下角“发消息”位置中心、“输入消息框”中心位置、“粘贴”中心位置、以及“发送”中心位置,在屏幕正上方可以显示出以上四步在屏幕中所点击的位置(请记录下来,然后分别将以上代码中的left1、top1,left2、top2,left3、top3,left4、top4改成记录的位置坐标(按顺序即可))(由于操作系统以及输入法的不一致,所需要点击的位置都是不一样的。)。在以上的代码中, 

cmd1 = 'adb shell input tap {x11} {y11}'.format(

        x11=swipe_x11,

        y11=swipe_y11,

    )
为点击屏幕某位置一下。



 cmd2 = 'adb shell input swipe {x12} {y12} {x22} {y22} {duration2}'.format(

        x12=swipe_x12,

        y12=swipe_y12,

        x22=swipe_x22,

        y22=swipe_y22,

        duration2=press_time2

    )

通过在很短的时间很小的区域内swipe(在手机屏幕上滑动,x12,y12为滑动的初始位置,x22,y22为滑动的末尾位置)模拟了长按的功能(由于本人是华为手机某输入法,通过长按输入框才能出现“粘贴”按钮),这个需要各位按照自己的情况而定哟。

然后,在之后的time.sleep()将点击屏幕动作进行间隔,特别是在点击右下角的“发消息”之后,弹出输入法需要一定的时间特别重要,否则之后几步就进行不下去了。(特别注意的是有部分手机还需要在os.popen(cmd4,'w')之后添加一个sleep)

在基本了解并做了一定更改之后,将数据线连接电脑,再运行adb.exe,fastboot.exe,

(https://github.com/wangshub/wechat_jump_game)(https://zhuanlan.zhihu.com/p/32452473)可以下载以上adb.exe、fastboot.exe以及另外两个dll文件即可运行adb以及fastboot。

然后运行python程序(F5)即可完成循环点击手机屏幕发送弹幕功能。

(本文仅供学习参考不做商业用途)

 转载请注明出处!!!

   

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息