计算1+2+3+…+99+100的值:
# -*- coding:utf8 -*-
import pyautogui
x = [0]*200
y = [0]*200
oneClick = pyautogui.locateCenterOnScreen('1.png')
zeroClick = pyautogui.locateCenterOnScreen('0.png')
for i in range(200):
if i == 199:
x[i] = pyautogui.locateCenterOnScreen('=.png')
else:
if i % 2 == 1:
x[i] = pyautogui.locateCenterOnScreen('+.png')
else:
xNumStr = str(((i / 2) + 1) % 10) + '.png'
# print xNumStr
x[i] = pyautogui.locateCenterOnScreen(xNumStr)
yNumStr = str(((i + 2) / 20) % 10) + '.png'
# print yNumStr
y[i] = pyautogui.locateCenterOnScreen(yNumStr)
for i in range(200):
if i == 198:
pyautogui.click(oneClick)
pyautogui.click(zeroClick)
pyautogui.click(zeroClick)
continue
if i > 17 and i % 2 == 0:
pyautogui.click(y[i])
pyautogui.click(x[i])
计算结果:
需要注意的是,要把调用点击的按键以.png的格式截图保存在文件目录下。