| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 
 | import pyautoguiimport time
 import xlrd
 import pyperclip
 
 
 
 
 
 def mouseClick(clickTimes,lOrR,img,reTry):
 if reTry == 1:
 while True:
 location=pyautogui.locateCenterOnScreen(img,confidence=0.9)
 if location is not None:
 
 pyautogui.click(location.x*.5,location.y*.5,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)
 break
 print("未找到匹配图片,0.1秒后重试")
 time.sleep(0.1)
 elif reTry == -1:
 while True:
 location=pyautogui.locateCenterOnScreen(img,confidence=0.9)
 if location is not None:
 pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)
 time.sleep(0.1)
 elif reTry > 1:
 i = 1
 while i < reTry + 1:
 location=pyautogui.locateCenterOnScreen(img,confidence=0.9)
 if location is not None:
 pyautogui.click(location.x,location.y,clicks=clickTimes,interval=0.2,duration=0.2,button=lOrR)
 print("重复")
 i += 1
 time.sleep(0.1)
 
 
 
 
 
 
 
 
 
 
 
 
 def dataCheck(sheet1):
 checkCmd = True
 
 if sheet1.nrows<2:
 print("没数据啊哥")
 checkCmd = False
 
 i = 1
 while i < sheet1.nrows:
 
 cmdType = sheet1.row(i)[0]
 if cmdType.ctype != 2 or (cmdType.value != 1.0 and cmdType.value != 2.0 and cmdType.value != 3.0
 and cmdType.value != 4.0 and cmdType.value != 5.0 and cmdType.value != 6.0 and cmdType.value != 7.0 ):
 print('第',i+1,"行,第1列数据有毛病")
 checkCmd = False
 
 cmdValue = sheet1.row(i)[1]
 
 if cmdType.value ==1.0 or cmdType.value == 2.0 or cmdType.value == 3.0:
 if cmdValue.ctype != 1:
 print('第',i+1,"行,第2列数据有毛病")
 checkCmd = False
 
 if cmdType.value == 4.0:
 if cmdValue.ctype == 0:
 print('第',i+1,"行,第2列数据有毛病")
 checkCmd = False
 
 if cmdType.value == 5.0:
 if cmdValue.ctype != 2:
 print('第',i+1,"行,第2列数据有毛病")
 checkCmd = False
 
 if cmdType.value == 6.0:
 if cmdValue.ctype != 2:
 print('第',i+1,"行,第2列数据有毛病")
 checkCmd = False
 i += 1
 return checkCmd
 
 
 def mainWork(img):
 i = 1
 while i < sheet1.nrows:
 
 cmdType = sheet1.row(i)[0]
 if cmdType.value == 1.0:
 
 img = sheet1.row(i)[1].value
 reTry = 1
 if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
 reTry = sheet1.row(i)[2].value
 mouseClick(1,"left",img,reTry)
 print("单击左键",img)
 
 elif cmdType.value == 2.0:
 
 img = sheet1.row(i)[1].value
 
 reTry = 1
 if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
 reTry = sheet1.row(i)[2].value
 mouseClick(2,"left",img,reTry)
 print("双击左键",img)
 
 elif cmdType.value == 3.0:
 
 img = sheet1.row(i)[1].value
 
 reTry = 1
 if sheet1.row(i)[2].ctype == 2 and sheet1.row(i)[2].value != 0:
 reTry = sheet1.row(i)[2].value
 mouseClick(1,"right",img,reTry)
 print("右键",img)
 
 elif cmdType.value == 4.0:
 inputValue = sheet1.row(i)[1].value
 pyperclip.copy(inputValue)
 pyautogui.hotkey('command','v')
 time.sleep(0.5)
 print("输入:",inputValue)
 
 elif cmdType.value == 5.0:
 
 waitTime = sheet1.row(i)[1].value
 time.sleep(waitTime)
 print("等待",waitTime,"秒")
 
 elif cmdType.value == 6.0:
 
 scroll = sheet1.row(i)[1].value
 pyautogui.scroll(int(scroll))
 print("滚轮滑动",int(scroll),"距离")
 
 elif cmdType.value == 7.0:
 
 scroll = sheet1.row(i)[1].value
 pyautogui.press(str(scroll))
 print("按键",str(scroll))
 i += 1
 
 if __name__ == '__main__':
 file = 'cmd.xls'
 
 wb = xlrd.open_workbook(filename=file)
 
 sheet1 = wb.sheet_by_index(0)
 
 checkCmd = dataCheck(sheet1)
 if checkCmd:
 key=input('选择功能: 1.做一次 2.一直循环 \n')
 if key=='1':
 
 mainWork(sheet1)
 elif key=='2':
 while True:
 mainWork(sheet1)
 time.sleep(0.1)
 print("等待0.1秒")
 else:
 print('输入有误或者已经退出!')
 
 
 |