def quit_monitor(self, event): if event == "keyboard_monitor_quit": self._mouse_monitor_quit = True mouse.Controller().click(mouse.Button.middle) print(event) elif event == "mouse_monitor_quit": self._keyboard_monitor_quit = True keyboard.Controller().press(keyboard.Key.f8) keyboard.Controller().release(keyboard.Key.f8) print(event) elif event == "monitor_quit": self._keyboard_monitor_quit = True self._mouse_monitor_quit = True mouse.Controller().click(mouse.Button.middle) sleep(0.1) keyboard.Controller().press(keyboard.Key.f8) sleep(0.1) keyboard.Controller().release(keyboard.Key.f8) if self._keyboard_monitor_quit and self._mouse_monitor_quit: print('monitor quit') return True else: return False
def __init__(self): os.system("title AxisInverter") if os.path.isfile("config.json"): with open("config.json", "r+") as config_file: file_content = config_file.read() banned_keys: dict = json.loads(file_content) else: with open("config.json", "w") as config_file_create: banned_keys = {"banned_keys": ["w", "a", "s", "d"]} json.dump(banned_keys, config_file_create) # List of keys that cannot be the switch. # I'm blocking "w", "a", "s", "d" just because they are used in games for movement. # Feel free to change it. self.parsed_keys = [] for key in banned_keys["banned_keys"]: self.parsed_keys.append(self.key_parser(key)) self.mouse = mouse.Controller() self.switch_set = False self.inverted = False self.thread = None self.first_usage = True self.switch = None self.mouse = mouse.Controller() self.minx, self.miny = (0, 0) self.maxx, self.maxy = pyautogui.size( ) # Getting the max x and max y of your screen. print("Press the key to choose a switch...") with keyboard.Listener( on_press=self.on_press, on_release=self.on_release) as keyboard_listener: keyboard_listener.join()
def on_click(x, y, button, pressed): global resetX resetX = ms.Controller().position[0] global resetY resetY = ms.Controller().position[1] if pressed: # Stop listener return False
def point(event): print(event.char) if event.char == 's': global start_point start_point = mouse.Controller().position startLbl.config(text=mouse.Controller().position) if event.char == 'e': global end_point end_point = mouse.Controller().position endLbl.config(text=mouse.Controller().position)
def point(event): print(event.char) if event.char == 's': global start_point start_point = mouse.Controller().position # 현재의 마우스 위치를 시작포인트로 지정 startLbl.config(text=mouse.Controller().position) # label 바꿔줌 if event.char == 'e': global end_point end_point = mouse.Controller().position # 현재의 마우스 위치를 끝포인트로 지정 endLbl.config(text=mouse.Controller().position) # 라벨 바꿔줌
def clicker(x, y): tim1 = time.time() print('Working...') time.sleep(2) mouse.Controller().position = (x, y) m = mouse.Controller() m.click(mouse.Button.left, 2) tim2 = time.time() print('Clicking is don. in ' + str((int(tim2) - int(tim1)))) time.sleep(0.5) print('Going to type words...')
def __init__(self, silence_time: int = 15, screen_width: int = 1920, screen_height: int = 1080, voice_mode: str = 'en'): """ create mouse instance, silence_time is default 15 for 5 sec if you want 10 sec set to 30 :param silence_time: :param screen_width: :param screen_height: :param voice_mode: """ self.__controller = mouse.Controller() super().__init__(controller=self.__controller) # set the mixer param for playing sound mixer.init() mixer.music.set_volume(0.5) # attribute self.__x: int = screen_width self.__y: int = screen_height self.__action: Action = Action(controller=self.__controller, screen_width=screen_width, screen_height=screen_height, voice_mode=voice_mode) self.__started: bool = False self.__can_speak = True self.__silence_time = silence_time
def on_shortcut_press(key): if key in keyboard_shortcut.combination: keyboard_shortcut.add_current_active_key(key) if all(k in keyboard_shortcut.current for k in keyboard_shortcut.combination): x, y = mouse.Controller().position provider.notify(EventCode.SHORTCUT, (x, y))
def __init__(self): self.on = False self.shooting = False self.gun = GunType(GUN) self.mouse = mouse.Controller() self.keyborad = keyboard.Controller() self.banner()
def start_mouse_listener(): global listener_is_done mouse = Mouse.Controller() with Mouse.Listener(on_click=on_click) as listener: while not listener_is_done: time.sleep(1)
def play(self): if len(self.keyEvents) == 0: print('There are no logged clicks/keypresses!') self.runLabel.setText('') return if self.mListener.running or self.kListener.running: self.stop_record() kController = keyboard.Controller() mController = mouse.Controller() for run in range(self.runTimes): rows = self.keyEvents[self.skipFirst:] if run == 0: rows = self.keyEvents for i, row in rows.iterrows(): sleep(row.WaitTime) if type(row.Coordinates) is tuple: mController.position = row.Coordinates if row.Type == 'Press': mController.press(row.Button) elif row.Type == 'Release': mController.release(row.Button) else: if row.Type == 'Press': kController.press(row.Button) elif row.Type == 'Release': kController.release(row.Button)
def autoThread(): global toggle global lastActionTime global threadactive controller = mouse.Controller() tracker = mouse.Listener(on_click = onMouseAction) tracker.start() print("Tracker has started!") lastActionTime = time.time() while toggle: time.sleep(1) a = time.time()-lastActionTime #print("Click Duration: %d" % a, end = "\r") inactiveTL["text"] = "Inactive for: {0:02d}:{1:02d}:{2:02d}".format( int(a // 3600), int(a // 60), int(a % 60) ) if time.time()-lastActionTime > settingsdict["regclickinterval"]: #print("You haven't clicked in a while. Clicking!") controller.click(mouse.Button.left,1) inactiveTL["text"] = "Inactive for: 0:0:0" print("Waiting for tracker to stop...") tracker.stop() threadactive = False activity["text"] = "Status: Standby" activity["background"] = "gray" btn["text"] = "Start" print("Tracker has stopped.")
def __init__(self): super().__init__(name="AutoClicker", icon="mouselogo.icns") default_value = 0.0 self.cps_value = AutoClicker.map_slider_to_cps(default_value) self.click_timer = rumps.Timer( lambda _: self.mouse.click(mouse.Button.left), 1 / self.cps_value) def timer_start(_): #print(rumps.timers()) self.click_timer.start() self.menu = [ rumps.MenuItem("Start", timer_start), None, "Stop key: esc", "Start key: \\", None, "cps_value", rumps.SliderMenuItem(dimensions=(180, 15), callback=self.change_cps, min_value=-1, max_value=5, value=default_value), None ] self.menu["cps_value"].title = f"CPS: {self.cps_value}" self.mouse = mouse.Controller() self.check_keys()
def __init__(self, stage=None): self._stage = stage self._kb_ctrl = kb.Controller() self._ms_ctrl = ms.Controller() self.mouse_listener = ms.Listener(on_click=self.on_click, on_move=self.on_move, on_scroll=self.on_scroll) self.keyboard_listener = kb.Listener(on_press=self.on_press, on_release=self.on_release)
def init(self): """ Runs some init functions. - Inits controller. """ self.controller = mouse.Controller()
def press_button(): mc = mouse.Controller() mc.press(mouse.Button.left) mc.release(mouse.Button.left) mc.click(mouse.Button.left, 2) # 双击 mc.scroll(0, 2) # 向下滚动两步
def __init__(self): super(Keyhole, self).__init__() self.qt_rects = [] self._awaiting_choice = False self.win = wx.Frame(None, wx.ID_ANY, "Overlay", style=wx.BORDER_NONE|wx.STAY_ON_TOP|wx.TRANSPARENT_WINDOW) self.win.SetTransparent(100) self.overlay = wx.Panel(self.win, -1, style=wx.TRANSPARENT_WINDOW) #self.overlay.SetTransparent(100) self.overlay.SetBackgroundColour('red') # grab screen res self.width, self.height = wx.GetDisplaySize() # eye position self._eye_x = 0 self._eye_y = 0 # setup tracker self.t = tr.find_all_eyetrackers()[0] self.t.subscribe_to(tr.EYETRACKER_GAZE_DATA, self.gaze_data_callback) # listen for keyboard events self.listener = keyboard.Listener( on_press=self._on_press, on_release=self._on_release) self.listener.start() self.mouse = mouse.Controller()
def __init__(self): self.keyboard = kk.Controller() self.keys = kk.Key self.mouse = mm.Controller() self.button = mm.Button self.lags = Lags()
def _anti_lockscreen(self): mctrl = mouse.Controller() refresh = min(self.pausetime / 1000, 1) refresh = max(refresh, 0.1) self._set_origin_time() t_diff = 0 while True: if self.need_break: self._app.mouseinfo.SetValue('') break time.sleep(refresh) current_pos = mctrl.position current_t = time.time() t_diff = current_t - self.origin_t if self._app.frame.IsShown(): self._app.mouseinfo.SetValue('鼠标位置:%s\n停留时间:%.2f' % (current_pos, t_diff)) if t_diff > self.pausetime: if self._am == self.AM_CLICK: mctrl.click(mouse.Button.left) elif self._am == self.AM_SCROLL: mctrl.scroll(0, 2) else: mctrl.move(-1, -1) self._set_origin_time()
def replay_actions(filename): global keyboard_ctrl global mouse_ctrl data = json.load(open(filename, "r")) mouse_ctrl = mouse.Controller() keyboard_ctrl = keyboard.Controller() for i, event in enumerate(data): start_action_time = time.time() if event["type"] == "on_move": on_move_handler(event) elif event["type"] == "on_click": on_click_handler(event) elif event["type"] == "on_scroll": on_scroll_handler(event) elif event["type"] == "on_press": on_press_handler(event) elif event["type"] == "on_release": on_release_handler(event) diff_time = 0 if i != len(data) - 1: diff_time = data[i + 1]["time"] - event["time"] time_to_wait = diff_time - (time.time() - start_action_time) if time_to_wait < 0: time_to_wait = 0 time.sleep(time_to_wait)
def __init__(self): fantome = str(Path.home()) + "/fantome" self.fichiers = get_all_files_list(fantome, [".json"]) print("Liste des fichiers à répéter") for fichier in self.fichiers: print(" ", fichier) self.kb_ctrl = keyboard.Controller() # #print(dir(self.kb_ctrl)) self.mouse_ctrl = mouse.Controller() self.loop = 1 self.backspace = 0 self.all_data = [] for fichier in self.fichiers: with open(fichier) as fd: data = fd.read() fd.close() data = json.loads(data) self.all_data.append(data) print("Longueur des datas =", len(data)) url = "labomedia.org" webbrowser.open(url, new=1, autoraise=True) self.start = 0 print("\n\n Ctrl + Alt + Q pour commencer à répéter ...") with keyboard.GlobalHotKeys({'<ctrl>+<alt>+q': self.on_activate_q})\ as hot: hot.join() print("je ne passe jamais par là")
def symbolOptions(self): """ 2nd function called in the main execution flow - after the user chooses a game-mode (Creates the GUI to let player(s) choose their symbols)""" self.optmode1.config(state='disabled') self.optmode2.config(state='disabled') self.modechoice.config(text="Game Mode") print("Game mode : %d" % self.gamemode.get()) self.symchoice = tk.LabelFrame(self.optpane, text="Choose a Symbol (Player 1) : ", padx=35) self.symchoice.pack(pady=5) if self.gamemode.get() == 2: self.mouse = mouse.Controller() self.symchoice.config(text=" Choose a Symbol ") self.playernames = {1: 'You', 2: 'The Computer'} self._loadImages() self.sym1 = tk.Button(self.symchoice, image=self.c, command=lambda: self.selectSymbol(self.sym1)) self.sym1.grid(column=0, row=0, pady=2, padx=2) self.sym2 = tk.Button(self.symchoice, image=self.x, command=lambda: self.selectSymbol(self.sym2)) self.sym2.grid(column=1, row=0, pady=2, padx=2) self.sym3 = tk.Button(self.symchoice, image=self.t, command=lambda: self.selectSymbol(self.sym3)) self.sym3.grid(column=2, row=0, pady=2, padx=2) self.sym4 = tk.Button(self.symchoice, image=self.s, command=lambda: self.selectSymbol(self.sym4)) self.sym4.grid(column=0, row=1, pady=2, padx=2) self.sym5 = tk.Button(self.symchoice, image=self.p, command=lambda: self.selectSymbol(self.sym5)) self.sym5.grid(column=1, row=1, pady=2, padx=2) self.sym6 = tk.Button(self.symchoice, image=self.h, command=lambda: self.selectSymbol(self.sym6)) self.sym6.grid(column=2, row=1, pady=2, padx=2) self.sym_btns = { self.sym1: self.c, self.sym2: self.x, self.sym3: self.t, self.sym4: self.s, self.sym5: self.p, self.sym6: self.h } self.plyr1chosen = False self.players = tk.Frame(self.gamepane) self.players.pack(pady=10, padx=5) self.player1 = tk.Label(self.players) self.player1.pack(side=LEFT, padx=10) self.player2 = tk.Label(self.players) self.player2.pack(side=RIGHT, padx=10)
def click(): mouse = ms.Controller() mouse.position = ( 122, 47 ) #where the refresh button is , if you don't know check out get mouse co-ords mouse.press(ms.Button.left) time.sleep(x) mouse.release(ms.Button.left)
def __init__(self, wndname="Diablo II", dpiaware=False): self.controller = mouse.Controller() self.mbutton = None self.loc = (0, 0) self.rloc = (0, 0) self.wndname = "Diablo II" self.dpiaware = dpiaware self.mscreen = D2Screen(self.wndname, dpiaware=self.dpiaware) self.update_window_position()
def drawWord(word, coords): cont = mouse.Controller() start = coords[word[0][0]][word[0][1]] cont.position = start cont.press(mouse.Button.left) for letter in word[1:]: coord = coords[letter[0]][letter[1]] dragMouse(cont, cont.position, coord) cont.release(mouse.Button.left)
def position_mouse(x_pos=0, y_pos=0, press_b1=False): ''' Move the mouse to a given location on screen and press left click if needed ''' mymouse = mouse.Controller() mymouse.position = (x_pos, y_pos) if press_b1: mymouse.press(mouse.Button.left) mymouse.release(mouse.Button.left)
def run(self, clicker): #pyautogui.click(clicks=self.click_count, interval=0.25) clicker = mouse.Controller() my_button = getattr(mouse.Button, self.button) time_interval = self.time / self.click_count for i in range(self.click_count): clicker.press(my_button) time.sleep(time_interval) clicker.release(my_button)
def receive_input(self): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sender: sender.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sender.bind((self.ip, self.port)) sender.listen() print('Waiting for connection on port(' + str(self.port) + ')...') conn, addr = sender.accept() with conn: print('Connected by', addr) width, height = pyautogui.size() print(width, height) mouse_controller = mouse.Controller() keyboard_controller = keyboard.Controller() mouse_buttons = [ mouse.Button.left, mouse.Button.middle, mouse.Button.right ] while True: #start_time = time.time() try: received_input = eval(self.recv_msg(conn).decode()) print(received_input) mouse_input = received_input['mouse_pos'] if mouse_input: mouse_input[0] = mouse_input[0] * width mouse_input[1] = mouse_input[1] * height mouse_controller.position = tuple(mouse_input) if received_input['mouse_down'] == 0: mouse_controller.press(mouse.Button.left) if received_input['mouse_up'] == 0: mouse_controller.release(mouse.Button.left) if received_input['mouse_down'] == 2: mouse_controller.press(mouse.Button.right) if received_input['mouse_up'] == 2: mouse_controller.release(mouse.Button.right) if received_input['keydown']: keyboard_controller.press( keyboard.KeyCode(received_input['keydown'])) if received_input['keyup']: keyboard_controller.release( keyboard.KeyCode(received_input['keyup'])) except Exception as e: print(e) pass
def run(self): k = keyboard.Controller() m = mouse.Controller() m.position = self.telegram_icon m.click(mouse.Button.left) time.sleep(0.1) with k.pressed(keyboard.Key.shift): # American keyboards can fug off k.press('7') k.release('7') k.type("newpack") time.sleep(0.1) k.press(keyboard.Key.enter) k.release(keyboard.Key.enter) time.sleep(0.1) def wait_for_enter(key): if key == keyboard.Key.enter: return False with keyboard.Listener(on_release=wait_for_enter) as listener: listener.join() time.sleep(0.5) for image in self.images: m.position = self.telegram_upload m.click(mouse.Button.left) time.sleep(0.5) m.position = image time.sleep(0.1) m.click(mouse.Button.left, 2) time.sleep(0.2) m.position = self.telegram_file time.sleep(0.1) m.click(mouse.Button.left) time.sleep(0.4) k.press(keyboard.Key.enter) time.sleep(0.2) k.release(keyboard.Key.enter) time.sleep(2) with k.pressed(keyboard.Key.shift): k.press('.') k.release('.') k.type("heart") with k.pressed(keyboard.Key.shift): k.press('.') k.release('.') time.sleep(0.1) k.press(keyboard.Key.enter) k.release(keyboard.Key.enter) time.sleep(0.2)
def run(): time.sleep(randint(30, 50)) helper = Helper(keyboard.Controller(), keyboard.Key) helper.alt_tab_step(10) helper.ctrl_pgDw_step(randint(5, 10)) for i in range(randint(10, 20)): mouse.Controller().move(randint(10, 100), randint(10, 100)) if datetime.datetime.now().hour >= 17 os.system("poweroff")