def main(): try: for o, i in enumerate('zxcasdqwe'): add_hotkey(f'alt+{i}', _send, args=(o + 1, )) print('Alt +', i, 'is', o) while input('Enter "y" to quit >').lower() != 'y': pass finally: clear_all_hotkeys()
def keyboard_listener() -> None: """ перехват keyboard-hotkey не работает в win10 x64: ctypes.ArgumentError: argument 3: <class 'OverflowError'>: int too long to convert """ try: keyboard.add_hotkey(lr_vars.FIND_PARAM_HOTKEY, get_param_clipboard_hotkey) yield finally: keyboard.clear_all_hotkeys() return
def keyboard_listener() -> None: """перехват keyboard-hotkey""" try: import keyboard except ImportError: lr_vars.Logger.info(Err) yield else: # hotkey keyboard.add_hotkey(lr_vars.FIND_PARAM_HOTKEY, get_param_clipboard_hotkey) yield keyboard.clear_all_hotkeys() return
def main(): app = QtWidgets.QApplication(sys.argv) window = GuiApp() keyboard.add_hotkey('shift+F1', hetKeySF1, args=(window, ), suppress=True, trigger_on_release=True) window.show() app.exec_() window.saveList() keyboard.clear_all_hotkeys() window.treadWorker.stop()
def getUserInput(): editing = True ret = [] def done(): nonlocal editing editing = False keyboard.add_hotkey('ctrl+enter',done) print("Lendo entrada, ctrl+enter para terminar") while editing: ret.append(input() + '\n') keyboard.clear_all_hotkeys() return ret
def choose(title: str, options: list, show_turn_back: bool = True, show_start_over: bool = True) -> str: """ Shows menu, where user can choose one of the presented options :param title: Menu title :param options: List of options :param show_turn_back: If True a 'Turn back' option will be shown :param show_start_over: If True a 'Start over' option will be shown :return: The option selected by user """ selected_options = [] print(f"{Fore.GREEN + chr(9679)} {Fore.WHITE + title}") for i in range(0, len(options)): keyboard.add_hotkey( str(i + 1), lambda index=i: perform_action(lambda: selected_options.append( options[index]))) __print_option(i + 1, options[i]) if show_turn_back: __print_option(9, selection_menu_additional_options[0]) keyboard.add_hotkey( '9', lambda: perform_action(lambda: selected_options.append( selection_menu_additional_options[0]))) if show_start_over: __print_option(0, selection_menu_additional_options[1]) keyboard.add_hotkey( '0', lambda: perform_action(lambda: selected_options.append( selection_menu_additional_options[1]))) while len(selected_options) == 0: time.sleep(0.1) print( f"You choose option '{Fore.GREEN + selected_options[0] + Fore.WHITE}'", '\n') keyboard.clear_all_hotkeys() helper.flush_input() # we should clear input buffer return selected_options[0]
def test_remove_hotkey(self): keyboard.press('a') keyboard.add_hotkey('a', self.fail) keyboard.clear_all_hotkeys() keyboard.press('a') keyboard.add_hotkey('a', self.fail) keyboard.clear_all_hotkeys() keyboard.press('a') keyboard.clear_all_hotkeys() keyboard.add_hotkey('a', self.fail) with self.assertRaises(ValueError): keyboard.remove_hotkey('b') keyboard.remove_hotkey('a')
def test_remove_hotkey(self): keyboard.press("a") keyboard.add_hotkey("a", self.fail) keyboard.clear_all_hotkeys() keyboard.press("a") keyboard.add_hotkey("a", self.fail) keyboard.clear_all_hotkeys() keyboard.press("a") keyboard.clear_all_hotkeys() keyboard.add_hotkey("a", self.fail) with self.assertRaises(ValueError): keyboard.remove_hotkey("b") keyboard.remove_hotkey("a")
env.render() next_state, reward, done, _ = env.step(action) memory.push([state, action, reward, next_state, done]) state = next_state T += 1 global_count += 1 if done: break print("\r push : %d/%d " % (global_count, args.learn_start), end='\r', flush=True) # print("\r push : ",global_count,'/',args.learn_start,end='\r',flush=True) if global_count > args.learn_start: break keyboard.clear_all_hotkeys() print('') for ii in range(1000): print(ii) agent.basic_learn(memory) if ii % 100 == 0: agent.target_dqn_update() """ main loop """ global_count = 0 episode = 0 while episode < args.max_episode_length: episode += 1 T = 0
def main(): args = anki_vector.util.parse_command_args() with anki_vector.Robot(args.serial, enable_camera_feed=True) as robot: def turn_left(): robot.behavior.turn_in_place(degrees(20)) def turn_far_left(): robot.behavior.turn_in_place(degrees(40)) def turn_right(): robot.behavior.turn_in_place(degrees(-20)) def turn_far_right(): robot.behavior.turn_in_place(degrees(-40)) def chase(): robot.behavior.drive_straight(distance_mm(200), speed_mmps(300)) stop = False head_angle = -5 print("Starting chase...") countdown = 5 meow_said = False while not stop: robot.behavior.set_head_angle(degrees(head_angle)) image = retrieve_new_image(robot) moved = True if red_splotch_detected_in_area(image, MIN_X, 127, 270, MAX_Y): print("Spotted dot nearby, to the far left") turn_far_left() meow_said = False elif red_splotch_detected_in_area(image, 127, 255, 270, MAX_Y): print("Spotted dot nearby, to the left") turn_left() meow_said = False elif red_splotch_detected_in_area(image, 255, 383, 270, MAX_Y): print("Captured the dot!") if not meow_said: robot.say_text("Meeow") meow_said = True moved = False elif red_splotch_detected_in_area(image, 383, 511, 270, MAX_Y): print("Spotted dot nearby, to the right") turn_right() meow_said = False elif red_splotch_detected_in_area(image, 511, MAX_X, 270, MAX_Y): print("Spotted dot nearby, to the far right") turn_far_right() meow_said = False elif red_splotch_detected_in_area(image, MIN_X, 127, MIN_Y, 269): print("Spotted dot in the distance, to the far left") turn_far_left() chase() meow_said = False elif red_splotch_detected_in_area(image, 127, 255, MIN_Y, 269): print("Spotted dot in the distance, to the left") turn_left() chase() meow_said = False elif red_splotch_detected_in_area(image, 255, 383, MIN_Y, 269): print("Spotted dot in the distance, straight ahead") chase() meow_said = False elif red_splotch_detected_in_area(image, 383, 511, MIN_Y, 269): print("Spotted dot in the distance, to the right") turn_right() chase() meow_said = False elif red_splotch_detected_in_area(image, 511, MAX_X, MIN_Y, 269): print("Spotted dot in the distance, to the far right") turn_far_right() chase() meow_said = False else: moved = False if not moved: countdown = countdown - 1 if countdown == 0: countdown = 1 head_angle = rotate_to_next_head_position(head_angle) if keyboard.is_pressed('x'): plt.imshow(image, interpolation='nearest') plt.show() keyboard.clear_all_hotkeys()
def HotKeyBind(): if self.activateHotkey.get() is True: keyboard.add_hotkey(self.copyhotkey, copyFile) else: keyboard.clear_all_hotkeys()
def clear(self): """Clear all hotkeys from system.""" self.log.info('clear all hotkeys...') keyboard.clear_all_hotkeys()
def stop_app(): global running logging.info('App stopped...') running = False keyboard.clear_all_hotkeys()