简体   繁体   English

我需要一个 Python 脚本到 output 文本从剪贴板粘贴到那里

[英]I need a Python script to output text from the clipboard when it is pasted there

I have code that displays the contents of a buffer without stopping.我有代码可以在不停止的情况下显示缓冲区的内容。 And I need to display this only when the buffer changes.而且我只需要在缓冲区更改时才显示它。 Help friends帮助朋友

import win32clipboard
import threading
import time

def clipboard():
    while True:
        win32clipboard.OpenClipboard()
        data = win32clipboard.GetClipboardData()
        win32clipboard.CloseClipboard()
        time.sleep(0.33)
        print(data)


clipboard = threading.Thread(target=clipboard)
clipboard.start()

Modified your clipboard() function.修改了您的clipboard() function。 Hope this works.希望这有效。

import win32clipboard
import threading
import time

def clipboard():
    prev_data = None
    while True:
        win32clipboard.OpenClipboard()
        data = win32clipboard.GetClipboardData()
        win32clipboard.CloseClipboard()
        time.sleep(0.33)

        if data != prev_data:
            print(data)
            prev_data = data


clipboard = threading.Thread(target=clipboard)
clipboard.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM