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 _execute_events(self, events): original = Clipboard() try: original.copy_from_system() except pywintypes.error, e: self._log.warning("Failed to store original clipboard contents:" " %s" % e)
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 SendCommandToClickByVoiceDragon(command): def go(): temporary = Clipboard({Clipboard.format_text: command}) temporary.copy_to_system() DragonKey('cs-dot/10').execute() try: original = Clipboard(from_system=True) go() original.copy_to_system() except Exception as e: go()
def copy_modify_paste(modifying_function): selected_text = utils.getSelectedText() if not selected_text: print "No selected text?" return modified_text = modifying_function(str(selected_text)) # tried to use the original clipboard here, but couldn't get it to "clear" -- some apps would # somehow get the original, unmodified text when the paste happened new_clipboard = Clipboard() new_clipboard.set_text(modified_text) new_clipboard.copy_to_system() Key("c-v").execute()
def _execute_events(self, events): original = Clipboard() original.copy_from_system() if self.format == win32con.CF_UNICODETEXT: events = unicode(events) elif self.format == win32con.CF_TEXT: events = str(events) clipboard = Clipboard(contents={self.format: events}) clipboard.copy_to_system() self.paste.execute() original.copy_to_system() return True
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_system_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) # Calculate keyboard events. use_hardware = self.require_hardware_events() keyboard_events = [] for key_symbol in events: # Get a Typeable object for each key symbol, if possible. typeable = self._get_typeable(key_symbol, use_hardware) # Raise an error message if a Typeable could not be retrieved. if typeable is None: error_message = ("Keyboard interface cannot type this" " character: %r" % key_symbol) raise ActionError(error_message) # Get keyboard events using the Typeable. keyboard_events.extend(typeable.events(self._pause)) # Send keyboard events. self._keyboard.send_keyboard_events(keyboard_events) return True
def readSelected(): clipBoardInstance = Clipboard(from_system=True) # make a temporary clipboard, with the message didn't found selected text, and clone it to system. temporary = Clipboard({Clipboard.format_unicode: u"didn't found selected text."}) temporary.copy_to_system() # copy new text to this set clipboard. If no text selected the text "didn't found selected text." remains on clipboard Key("c-c/25").execute() text = Clipboard(from_system=True).get_text() sayOutLoud(text.encode('utf8')) # set the first obtained clipboard back to the system. clipBoardInstance.copy_to_system()
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
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 save_to_clipboard(text): """Stores text to the clipboard""" clipboard = Clipboard(from_system=True) clipboard.set_text(text) clipboard.copy_to_system()
def go(): temporary = Clipboard({Clipboard.format_text: command}) temporary.copy_to_system() DragonKey('cs-dot/10').execute()
def save_clip(): """Stores the most recent clipboard item""" global clip clip = Clipboard(from_system=True).get_text()
def restore_clip(): """Restores the most recent clipboard item""" global clip clipboard = Clipboard(from_system=True) clipboard.set_text(clip) clipboard.copy_to_system()
def text_clip(): """Gets the most recent item from the clipboard as text""" return Clipboard(from_system=True).get_text()
def reverse_clip(): """Reverses the most recent clipboard item""" clip = text_clip() clipboard = Clipboard(from_system=True) clipboard.set_text(clip[::-1]) clipboard.copy_to_system()
class Paste(DynStrActionBase): """ Paste-from-clipboard action. Constructor arguments: - *contents* (*str*) -- contents to paste - *format* (*int*, Win32 clipboard format) -- clipboard format - *paste* (instance derived from *ActionBase*) -- paste action - *static* (boolean) -- flag indicating whether the specification contains dynamic elements This action inserts the given *contents* into the Windows system clipboard, and then performs the *paste* action to paste it into the foreground application. By default, the *paste* action is the :kbd:`Control-v` keystroke. The default clipboard format to use is the *Unicode* text format. """ # Default paste action. _default_format = win32con.CF_UNICODETEXT _default_paste = Key("c-v/20") def __init__(self, contents, format=None, paste=None, static=False): if not format: format = self._default_format if not paste: paste = self._default_paste if isinstance(contents, basestring): spec = contents self.contents = None else: spec = "" self.contents = contents self.format = format self.paste = paste DynStrActionBase.__init__(self, spec, static=static) def _parse_spec(self, spec): if self.contents: return self.contents else: return spec def _execute_events(self, events): original = Clipboard() try: original.copy_from_system() except pywintypes.error, e: self._log.warning("Failed to store original clipboard contents:" " %s" % e) if self.format == win32con.CF_UNICODETEXT: events = unicode(events) elif self.format == win32con.CF_TEXT: events = str(events) clipboard = Clipboard(contents={self.format: events}) clipboard.copy_to_system() self.paste.execute() original.copy_to_system() return True
def _execute_events(self, events): original = Clipboard() try: original.copy_from_system() except Exception as e: self._log.warning( "Failed to store original clipboard contents:" " %s", e) # Store the contents to copy (i.e. *events*) in a Clipboard # instance using the specified (or default) format. If *events* is # a dictionary, then pass it instead. if isinstance(events, dict): clipboard = Clipboard(contents=events) else: clipboard = Clipboard(contents={self.format: events}) # Copy the contents to the system clipboard and paste using the # paste action. clipboard.copy_to_system() self.paste.execute() # Restore the original clipboard contents afterwards. This should # clear the clipboard if we failed to store the original contents # above. original.copy_to_system() return True
def get_clipboard_as_text(): clipboard_instance = Clipboard() clipboard_instance.copy_from_system() return clipboard_instance.text