def recordkey(self): self.b.focus( ) # habe den focus hier auf den button gesetzt, damit die registrierte tasteneingabe (eventueller einzelner buchstabe oder zahl nicht im eingabefeld landen kann. Praktisch könnte zudem auch sein, wenn dann gleich durch bestätigen mit enter der Dialog Bestätigt werden kann.) test = keyboard.read_hotkey(suppress=False) self.e.delete(0, END) self.e.insert(0, test)
def generate_actions(): actionList = [] while True: print( "What type of action would you like to add?\n [1]. Key Press\n [2]. Key Release\n " "[3]. Key Press and Key Release\n [4]. Delay\n") acttype = int(input()) if acttype == 1 or acttype == 2 or acttype == 3: print("Press the hotkey you would like to press/release?") time.sleep(0.3) singleAction = [acttype, keyboard.read_hotkey(suppress=False)] elif acttype == 4: print("How long would the delay be (in milliseconds)?") delay = float(input()) singleAction = [acttype, delay] print("Your current action is: ") print(singleAction) print( "Are you sure you want to add this to the action string? [1. Yes, 2. No]" ) addAction = int(input()) if addAction == 1: actionList.append(singleAction) print("Action has successfully been added to the list") print("Would you like to add another action?\n [1]. Yes\n [2]. No") repeat = int(input()) if repeat == 2: return actionList
def _inputget(self, *args): while self.running and threading.main_thread().is_alive(): hotkey = keyboard.read_hotkey(False) self.curValue = hotkey self.shortcutPicker.text = _( "Press any key combination") + "\n" + hotkey time.sleep(0.5)
def callback(): try: keyboard.remove_hotkey(self.undo_split_hotkey) except AttributeError: pass self.undo_split_key = keyboard.read_hotkey(False) try: if self.undo_split_key == self.splitLineEdit.text( ) or self.undo_split_key == self.resetLineEdit.text( ) or self.undo_split_key == self.skipsplitLineEdit.text( ) or self.undo_split_key == self.undosplitLineEdit.text(): self.undo_split_hotkey = keyboard.add_hotkey( self.old_undo_split_key, self.undoSplit) self.afterSettingHotkeySignal.emit() return except AttributeError: self.afterSettingHotkeySignal.emit() return try: if '+' in self.undo_split_key: self.undo_split_hotkey = keyboard.add_hotkey( self.old_undo_split_key, self.undoSplit) self.afterSettingHotkeySignal.emit() return except AttributeError: self.afterSettingHotkeySignal.emit() return self.undo_split_hotkey = keyboard.add_hotkey( self.undo_split_key, self.undoSplit) self.undosplitLineEdit.setText(self.undo_split_key) self.old_undo_split_key = self.undo_split_key self.afterSettingHotkeySignal.emit() return
def read_hotkey(self): self.Clear() self.AppendText('Recording...') if self.isOneKey: shortcut = keyboard.read_key(False) else: shortcut = keyboard.read_hotkey(False) self.set_hotkey(shortcut)
def _selectHK3(self): print("_selectHK3") hkey = keyboard.read_hotkey() print("_selectHK3: hkey", hkey) self.config['Capture']['Hotkey AWindow'] = hkey self.saveini() self.hk3txt.set(self.config['Capture']['Hotkey AWindow']) keyboard.unhook_all_hotkeys()
def _selectHK2(self): print("_selectHK2") hkey = keyboard.read_hotkey() print("_selectHK2: hkey", hkey) self.config['Capture']['Hotkey FullScr'] = hkey self.saveini() self.hk2txt.set(self.config['Capture']['Hotkey FullScr']) keyboard.unhook_all_hotkeys()
def callback(): # try to remove the previously set hotkey if there is one. try: keyboard.remove_hotkey(self.split_hotkey) except AttributeError: pass #this error was coming up when loading the program and #the lineEdit area was empty (no hotkey set), then you #set one, reload the setting once back to blank works, #but if you click reload settings again, it errors #we can just have it pass, but don't want to throw in #generic exception here in case another one of these #pops up somewhere. except KeyError: pass # wait until user presses the hotkey, then keyboard module reads the input self.split_key = keyboard.read_hotkey(False) # If the key the user presses is equal to itself or another hotkey already set, # this causes issues. so here, it catches that, and will make no changes to the hotkey. try: if self.split_key == self.splitLineEdit.text() \ or self.split_key == self.resetLineEdit.text() \ or self.split_key == self.skipsplitLineEdit.text() \ or self.split_key == self.undosplitLineEdit.text() \ or self.split_key == self.pausehotkeyLineEdit.text(): self.split_hotkey = keyboard.add_hotkey( self.old_split_key, self.startAutoSplitter) self.afterSettingHotkeySignal.emit() return except AttributeError: self.afterSettingHotkeySignal.emit() return # keyboard module allows you to hit multiple keys for a hotkey. they are joined # together by +. If user hits two keys at the same time, make no changes to the # hotkey. A try and except is needed if a hotkey hasn't been set yet. I'm not # allowing for these multiple-key hotkeys because it can cause crashes, and # not many people are going to really use or need this. try: if '+' in self.split_key: self.split_hotkey = keyboard.add_hotkey( self.old_split_key, self.startAutoSplitter) self.afterSettingHotkeySignal.emit() return except AttributeError: self.afterSettingHotkeySignal.emit() return # add the key as the hotkey, set the text into the LineEdit, set it as old_xxx_key, # then emite a signal to re-enable some buttons and change some text in GUI. self.split_hotkey = keyboard.add_hotkey(self.split_key, self.startAutoSplitter) self.splitLineEdit.setText(self.split_key) self.old_split_key = self.split_key self.afterSettingHotkeySignal.emit() return
def main(): currDate = date.today() fileName = str(currDate.strftime("%d-%m-%Y") + '-VideoTitles.txt') options = Options() options.add_argument('--headless') options.add_argument('log-level=3') allVids = [] def getTitles(): vids = [] for vid in driver.find_elements_by_id('video-title'): title = vid.get_attribute('title') vids.append(title) return vids driver = webdriver.Chrome("chromedriver/chromedriver.exe", options=options) #driver = webdriver.PhantomJS(r"C:\Users\joe61081\Downloads\phantomjs-2.1.1-windows\bin\phantomjs.exe") driver.implicitly_wait(4) print("Connecting to youtube...") driver.get(uri) time.sleep(2) print("Loading Cookies...") for cookie in pickle.load(open("googleCookies.pkl", "rb")): cookie.pop("expiry", None) driver.add_cookie(cookie) # pickle.dump(driver.get_cookies(), open("googleCookies.pkl", "wb")) time.sleep(2) print("Signing in...") driver.execute_script("location.reload();") time.sleep(2) total = driver.find_element_by_xpath( '//*[@id="stats"]/yt-formatted-string[1]') strTotal = total.get_property('innerHTML') intTotal = int(''.join(filter(str.isdigit, strTotal))) print("Retrieving Titles...") while len(allVids) < intTotal: driver.execute_script( "window.scrollTo(0, document.documentElement.scrollHeight);") time.sleep(1) allVids = getTitles() print("Saving " + str(len(allVids)) + " Titles...") with open("titles/" + fileName, 'w', encoding='utf-8') as f: for vid in allVids: f.write("%s\n" % vid) print("Done, Saved to '" + fileName + "'!") print("Press Any Key To Exit...") if keyboard.read_hotkey() is not None: sys.exit(0)
def _selectHK1(self): print("_selectHK1") # self.hk1txt.set("<Press HotKey>") hkey = keyboard.read_hotkey() print("_selectHK1: hkey", hkey) self.config['Capture']['Hotkey Return'] = hkey self.saveini() self.hk1txt.set(self.config['Capture']['Hotkey Return']) keyboard.unhook_all_hotkeys()
def user_set_key(self, name): """Records a hotkey from the keyboard and adds it for a specified action. Args: name (str): Name of the action to add a key to. """ try: self.keys[name].append(keyboard.read_hotkey(suppress=True)) except: pass
def record_hotkey(self): rec = keyboard.read_hotkey(suppress=False).upper() keyboard.remove_hotkey(self.hotkey_string) keyboard.add_hotkey(rec, self.app.save_time) self.hotkey_label.config(text=rec) self.hotkey_string = rec label = self.action["text"][:-1] self.app.update_config("HOTKEYS", label, self.hotkey_string, "config.txt") self.app.update_dialogue("Hotkey has been set.")
def main(): print('Enter keybind:') key = keyboard.read_hotkey() hotkey = Bind(key) print("Type every weapon you want\nType done to get the command") weapon = '' while weapon.lower() != 'done': hotkey.addWeapon(weapon) weapon = input('>>> ') print(hotkey.command)
def set_key(self): sender = self.sender() input = keyboard.read_hotkey(suppress=False) if input != 'esc': if hotkey_delete_request(input): sender.key_code = None sender.setText(None) else: reply = QMessageBox.question(self, 'Save Key?', f'New Key: {input}.\n Save Key?') if reply == QMessageBox.Yes: sender.key_code = input sender.setText(input)
def set_hotkey2(self, event): event.widget.config(state=NORMAL) event.widget.delete(0, END) try: keyboard.unhook_all_hotkeys() except: pass self.hotkey = keyboard.read_hotkey() keyboard.stash_state() keyboard.add_hotkey(self.hotkey, self.capture, args=()) self.write_file() self.start_frame_label_2['text'] = self.hotkey.upper() event.widget.delete(0, END) event.widget.insert(0, self.hotkey.upper()) event.widget.config(state=DISABLED) self.calculate_width()
def _shortcutButtonClick(self): """ Shortcut button click event """ QMessageBox.information( self._view, "", _("Close this message and press a key or key combination. ")) key = keyboard.read_hotkey(True) if key == 'unknown': QMessageBox.information(self._view, "", _("Press again.")) key = keyboard.read_event(True) self._view.shortcutEdit.setText(str(key.scan_code)) else: self._view.shortcutEdit.setText(key)
def callback(): # try to remove the previously set hotkey if there is one. try: keyboard.remove_hotkey(self.split_hotkey) except AttributeError: pass # wait until user presses the hotkey, then keyboard module reads the input self.split_key = keyboard.read_hotkey(False) # If the key the user presses is equal to itself or another hotkey already set, # this causes issues. so here, it catches that, and will make no changes to the hotkey. try: if self.split_key == self.splitLineEdit.text( ) or self.split_key == self.resetLineEdit.text( ) or self.split_key == self.skipsplitLineEdit.text( ) or self.split_key == self.undosplitLineEdit.text(): self.split_hotkey = keyboard.add_hotkey( self.old_split_key, self.startAutoSplitter) self.afterSettingHotkeySignal.emit() return except AttributeError: self.afterSettingHotkeySignal.emit() return # keyboard module allows you to hit multiple keys for a hotkey. they are joined # together by +. If user hits two keys at the same time, make no changes to the # hotkey. A try and except is needed if a hotkey hasn't been set yet. try: if '+' in self.split_key: self.split_hotkey = keyboard.add_hotkey( self.old_split_key, self.startAutoSplitter) self.afterSettingHotkeySignal.emit() return except AttributeError: self.afterSettingHotkeySignal.emit() return # add the key as the hotkey, set the text into the LineEdit, set it as old_xxx_key, # then emite a signal to re-enable some buttons and change some text in GUI. self.split_hotkey = keyboard.add_hotkey(self.split_key, self.startAutoSplitter) self.splitLineEdit.setText(self.split_key) self.old_split_key = self.split_key self.afterSettingHotkeySignal.emit() return
def main(): try: while True: # read hotkey combination pressed by user keycombo = keyboard.read_hotkey() # assign the clipboard contents to 'word' word = pyperclip.paste() if keycombo == 'ctrl+g+h': # if clipboard wasn't blank, find definition of contents if word != None: definitions.lookup_definitions(word) elif keycombo == 'ctrl+g+y': # if clipboard wasn't blank, find synonym of contents if word != None: synonyms.lookup_synonyms(word) except KeyboardInterrupt: sys.exit()
def get_hotkey(): if not hasattr(get_hotkey, "last"): get_hotkey.last = {"hotkey": None, "delay": 0, "time": time.time()} hotkey = str(keyboard.read_hotkey(suppress=False)) if hotkey == get_hotkey.last["hotkey"]: if get_hotkey.last["time"] + get_hotkey.last["delay"] > time.time(): return None else: get_hotkey.last["time"] = time.time() get_hotkey.last["delay"] /= 1.5 else: get_hotkey.last["hotkey"] = hotkey get_hotkey.last["delay"] = 0.3 get_hotkey.last["time"] = time.time() return hotkey
def recordNew(rec): global until_key # Record keymap print('record keymap') #keymap = keyboard.record(until=until_key)[0].name keymap = keyboard.read_hotkey() print('{}'.format(keymap)) # Record the keystrokes print('record macro') #rec[keymap] = keyboard.record(until=until_key) #rec[keymap] = keyboard.record(until=until_key,trigger_on_release=True) rec[keymap] = keyboard.record(trigger_on_release=True) print(rec[keymap]) # Add hotkey keyboard.add_hotkey('{}'.format(keymap), lambda: keyboard.play(rec[keymap]))
def set_hotkey(self, hotkey): self.listener.stop() sender = self.sender() dialog = AddHotkeyDialog(self) dialog.show() QApplication.processEvents() input = keyboard.read_hotkey(suppress=False) dialog.close() if input != 'esc': if hotkey_delete_request(input): self.settings.hotkeys[hotkey] = '' self.buttons[hotkey].setText('') elif hotkey_is_numlock(input): scan_code = keyboard.key_to_scan_codes(input)[1] reply = QMessageBox.question( self, 'Save Hotkey?', f'New Hotkey: Num{input}.\n Save Hotkey?') if reply == QMessageBox.Yes: for k, hk in self.settings.hotkeys.items(): if hk == scan_code: self.settings.hotkeys[k] = '' self.buttons[k].setText('') self.settings.hotkeys[hotkey] = scan_code sender.setText(f'Num{input}') else: reply = QMessageBox.question( self, 'Save Hotkey?', f'New Hotkey: {input}.\n Save Hotkey?') if reply == QMessageBox.Yes: for k, hk in self.settings.hotkeys.items(): if hk == input: self.settings.hotkeys[k] = '' self.buttons[k].setText('') self.settings.hotkeys[hotkey] = input sender.setText(input) if not self.listener.paused: self.listener.start() # TODO: Wenn man seinen Pause key deleted elif self.settings.hotkeys['pause']: keyboard.add_hotkey(self.settings.hotkeys['pause'], self.listener.pause)
def detectUserKeyPress(self, lineEdits): self.successful = False # Try to remove the previously set hotkey if there is one try: keyboard.remove_hotkey(self.hotkey) except (AttributeError, KeyError, NameError): pass # wait until user presses the hotkey, then keyboard module reads the input self.key = keyboard.read_hotkey(False) # If the key the user presses is equal to itself or another hotkey already set, # this causes issues. So here, it catches that, and will make no changes to the hotkey try: for lineEdit in lineEdits: if lineEdit.text() == self.key: return except AttributeError: return # The keyboard module allows you to hit multiple keys for a hotkey. They are joined # together by a '+'. If user hits two keys at the same time, make no changes to the # hotkey. A try and except is needed if a hotkey hasn't been set yet. I'm not # allowing for these multiple-key hotkeys because it can cause crashes, and # not many people are going to really use or need this try: if '+' in self.key: return except AttributeError: return if self.key_press_function is not None: # Add the key as a hotkey self.hotkey = keyboard.add_hotkey(self.key, self.key_press_function) self.successful = True
def _read_hotkey(self): """ Callback used to get the hotkey pressed by the user. """ pop_up = tk.Toplevel() lbl = tk.Label( pop_up, text="Please insert an hotkey!", font=("Helvetica", 14)) lbl.pack(padx=5, pady=5) self.master.withdraw() pop_up.lift() self.master.update() hotkeys = self.master.get_hotkeys() hotkeys[self.__monitors_combo.current()] = \ keyboard.read_hotkey(suppress=False).split("+") self.master.set_hotkeys(hotkeys) txt = self._hk_txt(hotkeys[self.__monitors_combo.current()]) self.__label.config(text=txt) pop_up.destroy() self.master.show(False)
def createScript(self): while True: name = input('Name of the Script?\n') checker = Path("/scripts/" + name + ".py") if checker.is_file(): print("Already exists") else: break while True: firstkey = "" os.system("clear") time.sleep(0.5) print('Press and release your desired shortcut') shortcut = keyboard.read_hotkey() print('Shortcut selected:', shortcut) print('Name: {}\nKey: {}\nIs everything right ? (y)es/(n)o'.format( name, shortcut)) x = input("-->").lower() if not x == "n" or x == "no": open('scripts/' + name + '.py', 'w+') self.c.execute("INSERT INTO keys VALUES ('{}','{}')".format( shortcut, name)) self.conn.commit() break
def process(): queue.put(keyboard.read_hotkey())
import keyboard print('Press and release your desired shortcut: ') shortcut = keyboard.read_hotkey() print('Shortcut selected:', shortcut) def on_triggered(): print("Triggered!") keyboard.add_hotkey(shortcut, on_triggered) print("Press ESC to stop.") keyboard.wait('esc')
def capHotkey(): keyboard.stash_state() # This ensures no key sticking and is stupid save = keyboard.stash_state() # Save the keyboard state prior to hotkey intake hotkey = keyboard.read_hotkey() # Read the hotkey keyboard.restore_state(save) # Restore the keyboard state after hotkey intake return hotkey
def main(): push_to_talk_key = settings[0] VoiceProcess.lexer_sensitivity = settings[1] print( "W E L C O M E T O V O I C E M A C R O V E R S I O N 1 . 3 \n" ) while True: print( "MAIN MENU\n [1]. Create Commands\n [2]. View Commands\n [3]. Start Voice Macro\n [4]. Settings\n " "[5]. EXIT") main_menu = int(input()) if main_menu == 1: create_command() elif main_menu == 2: commands_keys = [] counter = 1 print("List of commands: ") for i in commands.keys(): print("[" + str(counter) + "]. " + i) commands_keys.append(i) counter += 1 print("Which command would you like to access? (-1 to return)") view_options = int(input()) if view_options < 0: pass else: chosen_command = commands_keys[view_options - 1] print("Command String: '" + chosen_command + "', Action String: " + str(commands.get(chosen_command))) print( "What would you like to do with this command?\n [1]. Delete\n " "[2]. Edit Key\n [3]. Edit key Values") view_options = int(input()) if view_options == 1: del commands[chosen_command] print("Command '" + chosen_command + "' has been deleted.") elif view_options == 2: new_command = generate_key() if new_command != '': commands[new_command] = commands.pop(chosen_command) elif view_options == 3: new_command = generate_actions() commands.update({str(chosen_command): new_command}) elif main_menu == 3: print( "Hold the '[" + push_to_talk_key + "]' to talk, and release to execute the command. Say 'Exit Macro' to end the Voice Macro" ) while True: command = '' while keyboard.is_pressed(push_to_talk_key): with sr.Microphone() as source: r.adjust_for_ambient_noise(source=source, duration=1) audio = r.listen(source) try: text = r.recognize_google(audio) command = text command = command.lower() print('You said : {}'.format(text)) voice_process = VoiceProcess(command, commands) command = voice_process.command_validator() except: command = "cannot be identified" if command == "exit macro": break execute_command(command) elif main_menu == 4: print( "What would you like to do ?\n [1]. Push to talk button\n [2]. Lexemizer tolerance\n " "[3]. Delete all macros") view_options = int(input()) if view_options == 1: print("Press the new key you want to choose") time.sleep(0.3) newkey = keyboard.read_hotkey(suppress=False) print("\nThe key that you pressed is [" + newkey + "] Are you sure ?\n [1] Yes \n [2] No") checker = int(input()) if checker == 1: push_to_talk_key = newkey print( "Push to talk button has successfully been changed into [" + push_to_talk_key + "].") settings[0] = push_to_talk_key print(push_to_talk_key) else: print( "Push to talk button change aborted, the previous button [" + push_to_talk_key + "] is still used.") elif view_options == 2: print( "TOLERANCE OPTION:\n [1]. Set Tolerance\n [2]. Reset to Default" ) input_choice = int(input()) if input_choice == 1: print("Please input the new tolerance level") lexer_sensitivity = int(input()) settings[1] = lexer_sensitivity VoiceProcess.lexer_sensitivity = settings[1] elif input_choice == 2: settings[1] = 45 VoiceProcess.lexer_sensitivity = settings[1] elif view_options == 3: commands.clear() print("All macros deleted") elif main_menu == 5: pickle_output = open("usermacro.pickle", "wb") pickle.dump(commands, pickle_output) pickle_output.close() pickle_output = open("settings.pickle", "wb") pickle.dump(settings, pickle_output) pickle_output.close() break
def keyInput(self): try: while True: self.ui.keyEdit.setText(keyboard.read_hotkey(False)) except: pass
def get_hkey(self, event): hkey = "" hkey = keyboard.read_hotkey(False) self.HotKeyKey.SetValue(hkey)