def add_close(_node): number = _node.words()[0] if number == "one": number = "1" else: number = "2" close_start = "{{c" + number + "::" Key("c-c/25").execute() Key("del").execute() clipboard = Clipboard() clipboard.copy_from_system() # populate this clipboard instance print(clipboard) close_word = clipboard.get_text() last = close_word[-1] second_to_last = close_word[-2] exclude_me = [",", ".", ";", "!", "?", ")"] s = "" if last == " ": if second_to_last in exclude_me: s = close_start + close_word[:-2] + "}}" + second_to_last + " " else: s = close_start + close_word[:-1] + "}}" + " " elif last in exclude_me: s = close_start + close_word[:-1] + "}}" + last else: s = close_start + close_word + "}}" # Text("{{c" + number + "::" + close_word[:-2] + "}}" + second_to_last + " ").execute() # Text("{{c" + number + "::" + close_word[:-1] + "}} ").execute() if s != "": Paste(s).execute()
def _process_recognition(self, value, extras): getPassword = Key("w-b/10, s-tab/10, right:8/10, enter, c-f/10") + value + Key('enter/10, escape/10, c-c/10, a-tab/10') getPassword.execute() clipboard = Clipboard() clipboard.copy_from_system(clear = True) password = clipboard.get_text() action = Text(password) action.execute()
def _process_recognition(self, value, extras): getPassword = Key( "w-b/10, s-tab/10, right:8/10, enter, c-f/10") + value + Key( 'enter/10, escape/10, c-c/10, a-tab/10') getPassword.execute() clipboard = Clipboard() clipboard.copy_from_system(clear=True) password = clipboard.get_text() action = Text(password) action.execute()
def _execute_events(self, events): """ Send keyboard events. If instance was initialized with *autofmt* True, then this method will mimic a word recognition and analyze its formatting so as to autoformat the text's spacing and capitalization before sending it as keyboard events. """ if self._autofmt: # Mimic a word, select and copy it to retrieve capitalization. get_engine().mimic("test") Key("cs-left, c-c/5").execute() word = Clipboard.get_text() # Inspect formatting of the mimicked word. index = word.find("test") if index == -1: index = word.find("Test") capitalize = True if index == -1: self._log.error("Failed to autoformat.") return False else: capitalize = False # Capitalize given text if necessary. text = self._spec if capitalize: text = text[0].capitalize() + text[1:] # Reconstruct autoformatted output and convert it # to keyboard events. prefix = word[:index] suffix = word[index + 4 :] events = self._parse_spec(prefix + text + suffix) # Send keyboard events. self._keyboard.send_keyboard_events(events) return True
def getSelectedText(): """ Get the currently selected text by copying it to the clipboard and pulling it from there. Preserve the original clipboard state. """ original = Clipboard(from_system=True) # print "original before copy: " + original.get_text() Key("c-c/5").execute() # note that trying to re-use this clipboard object after it's been # modified has caused me issues in the past -- seems to hold onto old values... just_copied = Clipboard() just_copied.copy_from_system() # print "original after copy: " + original.get_text() # print "just copied before original copy back: " + just_copied.get_text() original.copy_to_system() # restore the state of the clipboard return just_copied.get_text()
def _execute_events(self, events): """ Send keyboard events. If instance was initialized with *autofmt* True, then this method will mimic a word recognition and analyze its formatting so as to autoformat the text's spacing and capitalization before sending it as keyboard events. """ if self._autofmt: # Mimic a word, select and copy it to retrieve capitalization. get_engine().mimic("test") Key("cs-left, c-c/5").execute() word = Clipboard.get_text() # Inspect formatting of the mimicked word. index = word.find("test") if index == -1: index = word.find("Test") capitalize = True if index == -1: self._log.error("Failed to autoformat.") return False else: capitalize = False # Capitalize given text if necessary. text = self._spec if capitalize: text = text[0].capitalize() + text[1:] # Reconstruct autoformatted output and convert it # to keyboard events. prefix = word[:index] suffix = word[index + 4:] events = self._parse_spec(prefix + text + suffix) # Send keyboard events. self._keyboard.send_keyboard_events(events) return True