doOtherThing.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- coding: utf-8 -*-
  2. from scriptBase.imgFind import pcacc_img
  3. from scriptBase.mouseClick import pcacc_mouse
  4. import scriptBase.comon as comon
  5. import subprocess
  6. import pyautogui
  7. import random
  8. import string
  9. import time
  10. import pygetwindow as gw
  11. pic_notepad = 'other\other_notepad.png'
  12. pic_calc = 'other\other_calc.png'
  13. pic_edge = 'other\other_edge.png'
  14. # 生成随机字符串
  15. def generate_random_string(length):
  16. letters = string.ascii_letters + string.digits # 包含字母和数字的字符集
  17. return ''.join(random.choice(letters) for _ in range(length))
  18. def typeRandomStr(str):
  19. random_string = str
  20. if len(random_string) == 0:
  21. random_string = generate_random_string(random.randint(50, 100))
  22. for char in random_string:
  23. pyautogui.typewrite(char)
  24. delay = random.uniform(0.1, 0.3) # 生成随机延迟时间
  25. time.sleep(delay)
  26. class doOtherThing:
  27. @staticmethod
  28. def doWithNotePad():
  29. app_path = "notepad.exe"
  30. subprocess.Popen(app_path)
  31. comon.myTimeSleep_big()
  32. ret, position = pcacc_img.find_img_position(pic_notepad)
  33. if ret:
  34. point1, point2 = pcacc_img.choose_two_point_from_position(position)
  35. pcacc_mouse.click(point1[0], point1[1])
  36. comon.myTimeSleep_small()
  37. typeRandomStr('')
  38. pyautogui.scroll(random.randint(-20, 20))
  39. pcacc_mouse.drag(point2[0], point2[1])
  40. comon.myTimeSleep_big()
  41. subprocess.call(f"taskkill /f /im {app_path}")
  42. @staticmethod
  43. def doWithCalc():
  44. app_path = "calc.exe"
  45. subprocess.Popen(app_path)
  46. comon.myTimeSleep_big()
  47. if comon.waitClickImg_noWait(pic_calc, 1, 0):
  48. comon.myTimeSleep_big()
  49. operators = ['+', '-', '*', '/']
  50. random_str = str(random.randint(100, 200)) + random.choice(operators) + str(random.randint(100, 200)) + random.choice(operators)
  51. typeRandomStr(random_str)
  52. comon.myTimeSleep_big()
  53. subprocess.call(f"taskkill /f /im CalculatorApp.exe")
  54. @staticmethod
  55. def doWithEdge():
  56. if comon.waitClickImg_noWait(pic_edge, 2, 0):
  57. comon.myTimeSleep_big()
  58. pyautogui.scroll(random.randint(-20, 20))
  59. comon.myTimeSleep(60)
  60. pyautogui.scroll(random.randint(-20, 20))
  61. comon.myTimeSleep(60)
  62. comon.waitClickImg_noWait(pic_edge, 2, 0)
  63. OtherThingFuncArr = [doWithNotePad, doWithCalc]
  64. if __name__ == '__main__':
  65. doOtherThing.doWithEdge()