import pyautogui
import keyboard
def fixed_loop():
print(' 循环选择待命')
while True:
if keyboard.is_pressed('4'):
Royal = ['Royal.png', 'Royal1.png', 'Royal2.png', 'Royal3.png', 'Royal4.png', 'Royal5.png', 'Royal6.png']
x = 0
num = 0
for i in Royal:
pos = pyautogui.locateCenterOnScreen(Royal[num], grayscale=False, confidence=0.6, region=(50, 55, 310, 230))
num += 1
if pos is not None:
x = x + 1
print(x)
if x >= 1:
cloak_image = pyautogui.locateCenterOnScreen('Cloak.png', grayscale=False, confidence=0.6, region=(50, 55, 310, 230))
if cloak_image is None:
pyautogui.sleep(0.3)
print(' 有披风有红衣')
pyautogui.typewrite(['d', 'd', 'd', 'd'], 0.1)
pyautogui.typewrite(['w', 'w', 'w', 'w'], 0.1)
pyautogui.typewrite(['e', 'e', 'e', 'e'], 0.1)
pyautogui.typewrite(['f', 'f', 'f', 'f'], 0.1)
pyautogui.typewrite(['q', 'q', 'q', 'q'], 0.1)
print(' 固定起手结束')
break
if cloak_image is not None:
pyautogui.sleep(0.3)
print(' 无披风有红衣')
pyautogui.typewrite(['d', 'd', 'd', 'd'], 0.1)
pyautogui.typewrite(['w', 'w', 'w', 'w'], 0.1)
pyautogui.typewrite(['f', 'f', 'f', 'f'], 0.1)
pyautogui.typewrite(['q', 'q', 'q', 'q'], 0.1)
print(' 固定起手结束')
break
if x == 0:
cloak_image = pyautogui.locateCenterOnScreen('Cloak.png', grayscale=False, confidence=0.6, region=(50, 55, 310, 230))
if cloak_image is not None:
pyautogui.sleep(0.3)
print(' 无披风无红衣')
pyautogui.typewrite(['d', 'd', 'd', 'd'], 0.1)
pyautogui.typewrite(['r', 'r', 'r', 'r'], 0.1)
pyautogui.typewrite(['w', 'w', 'w', 'w'], 0.1)
pyautogui.typewrite(['f', 'f', 'f', 'f'], 0.1)
pyautogui.typewrite(['q', 'q', 'q', 'q'], 0.1)
print(' 固定起手结束')
break
if cloak_image is None:
pyautogui.sleep(0.3)
print(' 有披风无红衣')
pyautogui.typewrite(['d', 'd', 'd', 'd'], 0.1)
pyautogui.typewrite(['r', 'r', 'r', 'r'], 0.1)
pyautogui.typewrite(['w', 'w', 'w', 'w'], 0.1)
pyautogui.typewrite(['e', 'e', 'e', 'e'], 0.1)
pyautogui.typewrite(['f', 'f', 'f', 'f'], 0.1)
pyautogui.typewrite(['q', 'q', 'q', 'q'], 0.1)
print(' 固定起手结束')
break
if keyboard.is_pressed('5'):
print(' 进入智能循环')
break
else:
pyautogui.sleep(0.1)
if __name__ == '__main__':
fixed_loop()
def smart_loop():
while True:
FrostD = ['D.png', 'D1.png', 'D2.png', 'D3.png']
FrostF = ['F.png', 'F1.png', 'F2.png', 'F3.png']
FrostR = ['R.png', 'R1.png', 'R2.png', 'R3.png']
d = 0
f = 0
r = 0
num = 0
for i in FrostR:
pos = pyautogui.locateCenterOnScreen(FrostR[num], grayscale=False, confidence=0.8, region=(880, 1000, 80, 80))
num += 1
if pos is not None:
r = r + 1
num = 0
for i in FrostD:
pos = pyautogui.locateCenterOnScreen(FrostD[num], grayscale=False, confidence=0.8, region=(970, 1000, 80, 80))
num += 1
if pos is not None:
d = d + 1
num = 0
for i in FrostF:
pos = pyautogui.locateCenterOnScreen(FrostF[num], grayscale=False, confidence=0.8, region=(1050, 1000, 80, 80))
num += 1
if pos is not None:
f = f + 1
print(d, f, r)
if d >= 1:
pyautogui.sleep(0.4)
pyautogui.typewrite(['d', 'd', 'd', 'd'], 0.1)
if f >= 1:
pyautogui.sleep(0.4)
pyautogui.typewrite(['w', 'w', 'w', 'w'], 0.1)
pyautogui.typewrite(['f', 'f', 'f', 'f'], 0.1)
if r >= 1:
pyautogui.sleep(0.4)
pyautogui.typewrite(['r', 'r', 'r', 'r'], 0.1)
else:
pyautogui.typewrite(['q', 'q', 'q', 'q'], 0.01)
if keyboard.is_pressed('3'):
print(" 智能循环结束")
fixed_loop()
if keyboard.is_pressed('ctrl'):
print(' 暂停智能循环')
pyautogui.sleep(1)
while True:
if keyboard.is_pressed('ctrl'):
pyautogui.sleep(0.3)
else:
print(' 继续智能循环')
smart_loop()
if __name__ == '__main__':
smart_loop()
百度自学能力有限,需求就是上面的功能,简化高效的写法有没有.可加100