对VAT.exe软件操作,按esc杀掉python.exe进程
# -*- coding:utf8 -*- import datetime import os import random import time from threading import Thread from pynput.keyboard import Controller, Key, Listener import pyautogui # 监听按压 def on_press(key): try: print("正在按压:", format(key.char)) except AttributeError: print("正在按压:", format(key)) # 监听释放 def on_release(key): print("已经释放:", format(key)) if key == Key.esc: # 当输入esc键时,杀掉python36.exe进程 os.system('taskkill /f /im %s' % 'python.exe') # 停止监听 return False # 开始监听 def start_listen(): with Listener(on_press=on_press, on_release=on_release) as listener: listener.join() # 随机动作函数 def random_action(): while True: # 判断进程是否存在,不存在就退出脚本执行 p_name = 'VAT.exe' process_ = len(os.popen(f'tasklist | findstr {p_name}').readlines()) nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') if process_ == 0: print(f'检查不到程序{p_name},{nowTime}退出脚本。。。') os._exit(0) # 计算屏幕大小 x_screen, y_screen = pyautogui.size() print(x_screen, y_screen) # 随机生成屏幕坐标 x = random.randint(0, x_screen) y = random.randint(0, y_screen) # 随机动作间隔 time.sleep(0.5) # print(x, y) # 随机动作 action_num = random.randint(0, 10) if action_num in (1, 2, 6) and y <= 96: continue elif action_num == 0: # 单击 pyautogui.click(x, y) elif action_num == 1: print('# 双击') pyautogui.doubleClick(x, y) elif action_num == 2: print('# 三击') pyautogui.tripleClick(x, y) elif action_num == 3: print('# 中键') pyautogui.middleClick(x, y) elif action_num == 4: # todo:需要选择右键菜单中的选项 print('# 右键') pyautogui.rightClick(x, y) elif action_num == 5: print('# 鼠标滚轮') # scroll函数控制鼠标滚轮的滚动,amount_to_scroll参数表示滚动的格数。正数则页面向上滚动,负数则向下滚动: pyautogui.scroll(10, x, y) elif action_num == 6: print('# 拖拽') dragRel_type = random.randint(0, 8) # 往各个方向拖拽 if dragRel_type == 0: pyautogui.dragRel(100, 0, duration=0.2) elif dragRel_type == 1: pyautogui.dragRel(-100, 0, duration=0.2) elif dragRel_type == 2: pyautogui.dragRel(0, 100, duration=0.2) elif dragRel_type == 3: pyautogui.dragRel(0, -100, duration=0.2) elif dragRel_type == 4: pyautogui.dragRel(100, 100, duration=0.2) elif dragRel_type == 5: pyautogui.dragRel(-100, 100, duration=0.2) elif dragRel_type == 6: pyautogui.dragRel(100, -100, duration=0.2) elif dragRel_type == 7: pyautogui.dragRel(-100, -100, duration=0.2) elif action_num == 7: print('# 打字') pyautogui.typewrite('test123') elif action_num == 8: print('# 回车') pyautogui.press('enter') elif action_num == 9: print('# 快捷键') pyautogui.hotkey('ctrl', 'v') if __name__ == '__main__': # 现有两种方式退出运行:1.按esc;2.VAT.exe不存在 # 最小化cmd窗口 # pyautogui.hotkey('alt','space') # pyautogui.press('n') # 实例化键盘 kb = Controller() time.sleep(0.5) # 多线程 threads = [] # 开始监听,按esc退出监听 t1 = Thread(target=start_listen, args=()) t2 = Thread(target=random_action, args=()) threads.append(t1) threads.append(t2) # 启动线程 print('Threading start!') for t in threads: t.setDaemon(False) t.start() # t.join() time.sleep(0.2)
标签:exe,鼠标,screen,random,随机,key,import,print,软件 From: https://www.cnblogs.com/daizichuan/p/17488940.html