def setup(debug, speed): print("Setting up.") #Move mouse to game window and select window so it reads the keyboard mouse.position = (50, 50) time.sleep(.2) mouse.press(Button.left) time.sleep(.2) mouse.release(Button.left) #select the pokemon select_pokemon(speed) #Get screen shots for later comparison #We need multiple screen shots because of small variants in the timings # means the sometimes the pokemon sprite is in a different animation # state. If the initial image does not match the new one # taken when the find_shiny loop is running, it will stop the loop # in case there is a shiny pokemon. initial_img_arrs = list() for i in range(0, 20): initial_img_arrs.append(screen_shot(debug, "initial" + str(i))) #Restart the game time.sleep(1) keyboard.Controller().press(keyboard.Key.f12) time.sleep(.3) keyboard.Controller().release(keyboard.Key.f12) return initial_img_arrs
def find_shiny(initial_img_arrs, debug, speed): shiny_found = False count = 0 while shiny_found == False: skip_through_startup() print("Started Game.") select_pokemon(speed) print("Selected Pokemon.") count += 1 img_arr = screen_shot(debug, "check_shiny") print('Comparing to original to see if pokemon is shiny.') #Loop through the initial img set and see if any of them match the current screen shot #If there is a match found, then there is no shiny img_found = False for i in initial_img_arrs: if np.array_equal(i, img_arr, False): img_found = True print(f"Checked {count} pokemon so far.") #No matching image found, then there might be a shiny. if img_found == False: print("Possible shiny found, stoping script.") shiny_found = True else: #Restart the game time.sleep(.5) keyboard.Controller().press(keyboard.Key.f12) time.sleep(.3) keyboard.Controller().release(keyboard.Key.f12)
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 change_clicking_state(self): self.clicking = not self.clicking if (self.clicking): print("Bot Activado") else: print("Bot Desactivado") if (self.isMeditando): keyboard.Controller().press(self.teclaMeditar) keyboard.Controller().release(self.teclaMeditar) self.isMeditando = False
def run(self): while self.running: while self.clicking: mouse.position = self.lanzar_btn_pos mouse.click(self.button) mouse.position = self.start_pos time.sleep(0.05) mouse.click(self.button) self.isMeditando = True keyboard.Controller().press(self.teclaMeditar) time.sleep(0.025) keyboard.Controller().release(self.teclaMeditar) self.isMeditando = False time.sleep(0.05)
def pipe_outaudio_outdevice(oaq: Queue): global PYAUDIO global OUTPUT_DEVICE_NAME global VTTS_PTT_BUTTON while True: audio_binary = oaq.get() data, sample_rate = sf.read(io.BytesIO(audio_binary), dtype='float32') stream = PYAUDIO.open( format=PYAUDIO.get_format_from_width(4), channels=1, rate=sample_rate, output=True, output_device_index=get_device_index(OUTPUT_DEVICE_NAME)) frame_width = PYAUDIO.get_sample_size(PYAUDIO.get_format_from_width(4)) num_frames = int( len(data) / frame_width) * 4 # Have to multiply with ~4. Ah yes, very logical. keyboard_controller = keyboard.Controller() if VTTS_PTT_BUTTON: keyboard_controller.press(VTTS_PTT_BUTTON) stream.write(data, num_frames=num_frames) stream.close() if VTTS_PTT_BUTTON: keyboard_controller.release(VTTS_PTT_BUTTON)
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 __init__(self, all_states, is_calibrating=False): self.all_states = all_states self.screen = None self.in_block = False self.in_right = False self.is_calibrating = is_calibrating self.fire_mode_detect = WhiteDetector('fire-mode', 'white', min_white_rate['fire-mode']) self.in_tab_detect = WhiteDetector('in-tab', 'white', min_white_rate['in-tab']) # self.posture_detect = Detector('posture', 'white', min_white_rate['posture']) # self.in_scope_detect = Detector('in_scope') self.gun_detector = dict() self.gun_detector['name'] = WhiteDetector('name', 'white', min_white_rate['name']) self.gun_detector['scope'] = DiffDetector('scope', 'icon', default='1') self.gun_detector['muzzle'] = DiffDetector('muzzle', 'icon') self.gun_detector['grip'] = DiffDetector('grip', 'icon') self.gun_detector['butt'] = DiffDetector('butt', 'icon') # self.gun_detector['magazine'] = Detector('magazine', 'icon') self.key_listener = keyboard.Listener(on_press=self.on_press) self.mouse_listener = mouse.Listener(on_click=self.on_click) self.key_control = keyboard.Controller() self.key_listener.start() self.mouse_listener.start() self.temp_qobject = Temp_QObject()
def execute(): global text next_word = '' pyautogui.press('right', presses=1) pyautogui.press('backspace', presses=1) pyautogui.hotkey('ctrl', 'a') pyautogui.hotkey('ctrl', 'c') pyautogui.press('right', presses=2) text = pyperclip.paste() text = text.replace(',', ' , ') text = text.replace('.', ' . ') text = ' '.join(text.split(' ')[-10:]) #print("Text: "+text) if (text[-1] != ' '): next_word = ' ' next_word += str( pyautogui.confirm(text='Choose one of the suggested', title='Suggested Words', buttons=complete(text))) + ' ' if ('None' not in next_word): if ('.' in text[-3:]): if (next_word[0] != ' '): next_word = next_word[0].upper() + next_word[1:] else: next_word = next_word[0:2].upper() + next_word[2:] keyboard.Controller().type(next_word) time.sleep(0.2) pyperclip.copy('') text = ''
def __init__(self): self.on = False self.shooting = False self.gun = GunType(GUN) self.mouse = mouse.Controller() self.keyborad = keyboard.Controller() self.banner()
def clearShops(): keyboardTarget = keyboard.Controller() with keyboardTarget.pressed(keyboard.Key.alt): keyboardTarget.press('h') keyboardTarget.release('h') keyboardTarget.press('h') keyboardTarget.release('h')
def kb_press(*keys): kb = keyboard.Controller() for key in keys: kb.press(key) for key in keys: kb.release(key) return
def task_switch(): key_ctrl=keyboard.Controller() key_ctrl.press(keyboard.Key.alt) key_ctrl.press(keyboard.Key.tab) time.sleep(0.1) key_ctrl.release(keyboard.Key.alt) key_ctrl.release(keyboard.Key.tab)
def press_single_key(input_key): ''' Press a single key ''' mykeyboard = keyboard.Controller() mykeyboard.press(input_key) mykeyboard.release(input_key)
def main(): controller = keyboard.Controller() # Creating a listener for the keyboard. listener = keyboard.Listener(on_press=keyboard_clicked) listener.start() listener.join()
def main(): # Set up the Leap Motion sensor. listener = Listener() controller = Leap.Controller() controller.set_policy(Leap.Controller.POLICY_BACKGROUND_FRAMES) controller.set_policy(Leap.Controller.POLICY_IMAGES) # controller.config.save() # Have the listener receive events from the controller. controller.add_listener(listener) controller.config.save() # Set up the pynput controller. global keyboard keyboard = Keyboard.Controller() global k k = PyKeyboard() while True: time.sleep(100)
def on_activate(): log.info('Global hotkey activated') if SYSTEM == "Darwin": keyboard_controller = keyboard.Controller() with keyboard_controller.pressed(keyboard.Key.cmd): keyboard_controller.press('c') keyboard_controller.release('c') elif SYSTEM == "Windows": keyboard.send('ctrl+c') else: return time.sleep(0.5) variable = pyperclip.paste() fragment = globe.blueprint.get_fragment(**{'name': variable}) pyperclip.copy(fragment) time.sleep(0.5) if SYSTEM == "Darwin": with keyboard_controller.pressed(keyboard.Key.cmd): keyboard_controller.press('v') keyboard_controller.release('v') elif SYSTEM == "Windows": keyboard.send('ctrl+v') time.sleep(0.5) if SYSTEM == "Darwin": pyperclip.copy('') globe.blueprint.do_macro(name=variable) log.info('Global hotkey function terminated')
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 __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 execute(): dec = keyboard.KeyCode(65454) kc = keyboard.Controller() time.sleep(0.5) kc.press(dec) time.sleep(0.2) kc.release(dec)
def start(self): listener = keyboard.Listener(on_press=on_press) listener.start() ###### start keyboard listener in a separate thread ####### Switch between 'command' and' writing' modes by pressing the shift key 2 consecutive times keyboardController = keyboard.Controller( ) ####### object to control the keyboard, used in 'writing' mode while True: recording = self.recordOnSound(timeOut=1) if haltMode == False: speech = self.speechToText(recording).lower().strip() if commandMode == True: words = speech.split(' ') order = words[0] if len(words) > 1: args = ' '.join(words[1::]) else: args = '#empty#' try: cmd = self.commandTable.loc[args, order] p = Popen(cmd, shell=True) except KeyError: print('Command error: "%s" command not available' % speech) continue except Exception as e: print(e) else: if not (speech == '*error*'): keyboardController.type(speech + ' ')
def __init__(self): self.keyboard = kk.Controller() self.keys = kk.Key self.mouse = mm.Controller() self.button = mm.Button self.lags = Lags()
def run(shortcut1, shortcut2 = None): special_words = [w.lower() for w in load_special_words()] special_words = { normalize(w) : w for w in special_words } special_words_buffer = deque() def dec(*args, **kwargs): def f(): x = do_stuff(*args, **kwargs) if x is not None: special_words_buffer.append(x + (time.time(), )) return f def update_buffer(): nonlocal special_words, special_words_buffer did_something = False while special_words_buffer and time.time() - special_words_buffer[0][2] > 10: i, j, k = special_words_buffer.popleft() special_words[i] = j did_something = True for acc in ACCENTS: if j[-1] in acc[0 : 2]: del special_words[i] break if did_something: save_special_words(special_words.values()) print(special_words) hotkeys = { shortcut1 : dec(1, special_words), 'default' : update_buffer } if shortcut2: hotkeys[shortcut2] = dec(-1) try: with MultipleHotKeys(hotkeys) as ghk: ghk.join() except Exception: C = keyboard.Controller() for k in [Key.shift, Key.ctrl, Key.alt]: C.release(k)
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 __presskeys(self, keys): contr = keyboard.Controller() hotkeys = keyboard.HotKey.parse(keys) for hotkey in hotkeys: contr.press(hotkey) hotkeys.reverse() for hotkey in hotkeys: contr.release(hotkey)
def ctrl_w(delay): time.sleep(delay) key_ctrl=keyboard.Controller() key_ctrl.press(keyboard.Key.ctrl) key_ctrl.press('w') time.sleep(0.1) key_ctrl.release(keyboard.Key.alt) key_ctrl.release('w')
def iconClied(self, reason): k = keyboard.Controller() if reason in ( PySide6.QtWidgets.QSystemTrayIcon.ActivationReason.Trigger, PySide6.QtWidgets.QSystemTrayIcon.ActivationReason.DoubleClick ): k.press(keyboard.Key.caps_lock) k.release(keyboard.Key.caps_lock)
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")