def __init__(self, conn, addr): self.mouse = MouseController() self.keyboard = KeyoardController() threading.Thread.__init__(self) self.conn = conn self.addr = addr print("Accepting connection from: {0}:{1} ".format(*self.addr))
def start(self): self._listener_keyboard = KeyboardListener(on_release=self.on_keyboard_release) self._listener_keyboard.start() if input("please input \"MOUSE\" to start mouse function:\n") == "MOUSE": self._listener_mouse = MouseListener(on_click=self.on_click) self._listener_mouse.start() self.ctl_mouse = MouseController()
def click_left_button(): mouse_controller = MouseController() while True: if Shared.is_pressed_f3: mouse_controller.press(Button.left) mouse_controller.release(Button.left) time.sleep(0.1)
def __init__(self,PixelConversion=1): """Init a MovementController instance. Keyword Arguments: PixelConversion -- 1 for PC, 2 for Retina Display """ self.pixelConversion = PixelConversion self.keyboard = KeyboardController() self.mouse = MouseController()
def __init__(self): self.replay_file = self.LOG_FILE_NAME self.keyboard = KeyboardController() self.mouse = MouseController() self.INPUT_LIST = [ self.KEY_PRESS, self.KEY_RELEASE, self.MOUSE_CLICK, self.MOUSE_SCROLL, ]
def keystroke_action(inject): keyboard = KeyboardController() mouse = MouseController() for command in inject: command = command.split(' ') c_type, c_data = command[0], command[1] if c_type == 'press': try: c_data = eval(f'Key.{c_data}') except: pass finally: keyboard.press(c_data) keyboard.release(c_data) elif c_type == 'hold': try: c_data = eval(f'Key.{c_data}') except: pass finally: keyboard.press(c_data) elif c_type == 'release': try: c_data = eval(f'Key.{c_data}') except: pass finally: keyboard.release(c_data) elif c_type == 'type': keyboard.type(' '.join(command[1:])) elif c_type == 'position': mouse.position = [int(position) for position in c_data.split(',')] elif c_type == 'move': move_positions = [int(position) for position in c_data.split(',')] mouse.move(move_positions[0], move_positions[1]) elif c_type == 'mhold': mouse.press(eval(f'Button.{c_data}')) elif c_type == 'mrelease': mouse.release(eval(f'Button.{c_data}')) elif c_type == 'click': mouse.press(eval(f'Button.{c_data}')) mouse.release(eval(f'Button.{c_data}')) elif c_type == 'dclick': mouse.click(eval(f'Button.{c_data}'), 2) elif c_type == 'scroll': scroll_positions = [int(position) for position in c_data.split(',')] mouse.scroll(scroll_positions[0], scroll_positions[1]) elif c_type == 'sleep': time.sleep(float(c_data)) else: raise Exception('Invalid keystroke command')
def main(): """ Fishing with simple model (color channels are untouched). """ model = tf.keras.models.load_model("train_model/Model/trained_model") classes = ["cast", "pull", "wait"] # mss is fast sct = mss.mss() # set correct monitor location! monitor = {"top": 550, "left": 430, "width": 200, "height": 450} mouse = MouseController() while True: t_1 = time.time() # using little sleep to keep reaction time close to human time.sleep(0.1) # python-mss.readthedocs.io/examples.html sct_img = sct.grab(monitor) pil_img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX") keras_frame = keras.preprocessing.image.img_to_array(pil_img) frame_batch = tf.expand_dims(keras_frame, 0) prediction = model.predict(frame_batch) pred_class = classes[np.argmax(prediction)] print() print(pred_class) frame = np.array(pil_img) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) frame = cv2.putText(frame, pred_class, (5, 25), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, cv2.LINE_AA) cv2.imshow('monitor', frame) cv2.waitKey(1) print("fps:", 1 // (time.time() - t_1)) if pred_class == "cast": mouse.click(Button.right, 1) time.sleep(2.5) # sleep while line is setting in game elif pred_class == "pull": mouse.click(Button.right, 1) time.sleep(2.5) # sleep while line is setting in game else: # no need for action, just wait pass
def auto_roll(self, area): # 自动滚动模式 x, y, w, h = area self.rollermask.tips.setText("单击停止") QApplication.processEvents() speed = round(1 / self.roll_speed, 2) screen = QApplication.primaryScreen() winid = QApplication.desktop().winId() def onclick(x, y, button, pressed): # 点击退出的函数句柄 if pressed: print("click to stop") self.in_rolling = False listener.stop() controler = MouseController() # 鼠标控制器 listener = MouseListenner(on_click=onclick) # 鼠标监听器 self.match_thread = Commen_Thread( self.match_and_merge) # 把match_and_merge放入一个线程中 self.in_rolling = True i = 0 controler.position = (area[0] + int(area[2] / 2), area[1] + int(area[3] / 2)) # 控制鼠标点击到滚动区域中心 oldimg = Image.new("RGB", (128, 128), "#FF0f00") listener.start() while self.in_rolling: st = time.time() pix = screen.grabWindow(winid, x, y, w, h) # 截屏 newimg = Image.fromqpixmap(pix) # 转化为pil的格式 img = cv2.cvtColor(asarray(newimg), cv2.COLOR_RGB2BGR) self.img_list.append(img) # 图片数据存入self.img_list中被后台的拼接线程使用 # cv2.imshow("FSd", img) # cv2.waitKey(0) if i >= 1: if i == 1: self.match_thread.start() # 当截第二张图片时拼接线程才启动 if self.is_same(oldimg, newimg): # 每帧检查是否停止 self.in_rolling = False i += 1 break oldimg = newimg controler.scroll(dx=0, dy=-3) # 控制鼠标滚动 time.sleep(speed) # 通过sleep控制自动滚动速度 # cv2.imwrite('j_temp/{0}.png'.format(i), img) i += 1 print("结束滚动,共截屏{}张".format(i)) listener.stop() # self.showrect.hide() self.match_thread.wait()
def auto_roll(self, area): x, y, w, h = area self.tips.setText("单击停止") QApplication.processEvents() speed = round(1 / self.roll_speed, 2) screen = QApplication.primaryScreen() winid = QApplication.desktop().winId() def onclick(x, y, button, pressed): if pressed: print("click to stop") self.in_rolling = False listener.stop() controler = MouseController() listener = MouseListenner(on_click=onclick) self.match_thread = Commen_Thread(self.match_and_merge) self.in_rolling = True i = 0 controler.position = (area[0] + int(area[2] / 2), area[1] + int(area[3] / 2)) oldimg = Image.new("RGB", (128, 128), "#FF0f00") listener.start() while self.in_rolling: st = time.time() pix = screen.grabWindow(winid, x, y, w, h) newimg = Image.fromqpixmap(pix) img = cv2.cvtColor(np.asarray(newimg), cv2.COLOR_RGB2BGR) self.img_list.append(img) # cv2.imshow("FSd", img) # cv2.waitKey(0) if i >= 1: if i == 1: self.match_thread.start() if self.is_same(oldimg, newimg): # 每帧检查是否停止 self.in_rolling = False i += 1 break oldimg = newimg controler.scroll(dx=0, dy=-3) time.sleep(speed) # cv2.imwrite('j_temp/{0}.png'.format(i), img) i += 1 print("结束滚动,共截屏{}张".format(i)) listener.stop() self.showrect.hide() self.match_thread.wait() self.showm_signal.emit("长截图完成")
def __init__(self, parent_ui=None, config=Config()): super(AutoClickerThread, self).__init__() self.ui = parent_ui self.config = config self.thread = None self._stop_event = Event() self.mouse_button = None self.current_keys = set() self.accepted_keys = set() self.reload_config() self.activated = False self.mouse_controller = MouseController() self.keyboard_controller = KeyboardController() self.last_state = False self.sequence_index = 0 self.sequence_length = len(self.config.output_sequence)
def run(self): if not os.path.exists(self.file_name): os.mkdir(self.file_name) with open(self.file_name, 'r', encoding='utf-8') as file: mouse_exec = MouseController() line = file.readline() # if not line: # print('no mouse') # return while line: obj = json.loads(line) # print(obj) if obj['name'] == 'mouse': delay = obj['time'] / self.speed if delay < 0.1: high_precision_delay(delay) elif 1 > delay > 0.1: time.sleep(delay) else: self.listening_sleep(delay) if obj['event'] == 'move': mouse_exec.position = (obj['location']['x'], obj['location']['y']) # print(1) elif obj['event'] == 'click': if obj['action']: # time.sleep(obj['time']) if obj['target'] == 'left': mouse_exec.press(Button.left) else: mouse_exec.press(Button.right) else: if obj['target'] == 'left': mouse_exec.release(Button.left) else: mouse_exec.release(Button.right) elif obj['event'] == 'scroll': # time.sleep(obj['time']) mouse_exec.scroll(20, obj['location']['y']) if self.stoper: print('鼠标stoper') self.stoper = False break line = file.readline()
class KeyPresser(Thread): gcd = 1 kc = KeyboardController() mc = MouseController() c = RGB(255, 0, 0) dc = GetDC(0) macro = "" def __init__(self, m): print(macros[m]) self.macro = m Thread.__init__(self) self.daemon = True self.start() def indicator(self): width = int(GetSystemMetrics(0) / 2) for i in range(width - 12, width + 12): for j in range(24): SetPixel(self.dc, i, j, self.c) def run(self): while True: global run, pause, macros if running: self.indicator() if not pause: for macro in macros[self.macro]: if isinstance(macro, tuple): self.mc.scroll(macro[0], macro[1]) else: self.kc.press(macro) self.kc.release(macro) sleep(0.1) sleep(self.gcd) else: sleep(2)